Module: RSS::Maker::DCTerms::PropertyModel

Included in:
ChannelBase, ImageBase, ItemsBase::ItemBase, TextinputBase
Defined in:
lib/rss/maker/dcterms.rb

Class Method Summary collapse

Class Method Details

.append_features(klass) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rss/maker/dcterms.rb', line 9

def append_features(klass)
  super

  ::RSS::DCTerms::PropertyModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
    plural_name ||= "#{name}s"
    full_name = "#{RSS::DCTerms::PREFIX}_#{name}"
    full_plural_name = "#{RSS::DCTerms::PREFIX}_#{plural_name}"
    plural_klass_name = "DCTerms#{Utils.to_class_name(plural_name)}"
    klass.def_classed_elements full_name, 'value', plural_klass_name,
                               full_plural_name, name
    klass.module_eval(<<-EOC)
      def new_#{full_name}(value=nil)
        _#{full_name} = #{full_plural_name}.new_#{name}
        _#{full_name}.value = value
        if block_given?
          yield _#{full_name}
        else
          _#{full_name}
        end
      end
    EOC
  end
end

.install_dcterms_core(klass) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rss/maker/dcterms.rb', line 33

def install_dcterms_core(klass)
  ::RSS::DCTerms::PropertyModel::ELEMENT_NAME_INFOS.each do |name, plural_name|
    plural_name ||= "#{name}s"
    klass_name = Utils.to_class_name(name)
    full_klass_name = "DCTerms#{klass_name}"
    plural_klass_name = "DCTerms#{Utils.to_class_name(plural_name)}"
    klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
    class #{plural_klass_name} < #{plural_klass_name}Base
      class #{full_klass_name} < #{full_klass_name}Base
      end
      #{klass_name} = #{full_klass_name}
    end
EOC
  end
end