Module: RSS::Maker::ITunesBaseModel

Included in:
ITunesChannelModel, ITunesItemModel
Defined in:
lib/rss/maker/itunes.rb

Instance Method Summary collapse

Instance Method Details

#def_class_accessor(klass, name, type, *args) ⇒ Object



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

def def_class_accessor(klass, name, type, *args)
  name = name.gsub(/-/, "_").gsub(/^itunes_/, '')
  full_name = "#{RSS::ITUNES_PREFIX}_#{name}"
  case type
  when nil
    klass.def_other_element(full_name)
  when :yes_other
    def_yes_other_accessor(klass, full_name)
  when :explicit_clean_other
    def_explicit_clean_other_accessor(klass, full_name)
  when :csv
    def_csv_accessor(klass, full_name)
  when :element, :attribute
    recommended_attribute_name, = *args
    klass_name = "ITunes#{Utils.to_class_name(name)}"
    klass.def_classed_element(full_name, klass_name,
                              recommended_attribute_name)
  when :elements
    plural_name, recommended_attribute_name = args
    plural_name ||= "#{name}s"
    full_plural_name = "#{RSS::ITUNES_PREFIX}_#{plural_name}"
    klass_name = "ITunes#{Utils.to_class_name(name)}"
    plural_klass_name = "ITunes#{Utils.to_class_name(plural_name)}"
    def_elements_class_accessor(klass, name, full_name, full_plural_name,
                                klass_name, plural_klass_name,
                                recommended_attribute_name)
  end
end

#def_csv_accessor(klass, full_name) ⇒ Object



55
56
57
# File 'lib/rss/maker/itunes.rb', line 55

def def_csv_accessor(klass, full_name)
  klass.def_csv_element(full_name)
end

#def_elements_class_accessor(klass, name, full_name, full_plural_name, klass_name, plural_klass_name, recommended_attribute_name = nil) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rss/maker/itunes.rb', line 59

def def_elements_class_accessor(klass, name, full_name, full_plural_name,
                                klass_name, plural_klass_name,
                                recommended_attribute_name=nil)
  if recommended_attribute_name
    klass.def_classed_elements(full_name, recommended_attribute_name,
                               plural_klass_name, full_plural_name)
  else
    klass.def_classed_element(full_plural_name, plural_klass_name)
  end
  klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
    def new_#{full_name}(text=nil)
      #{full_name} = @#{full_plural_name}.new_#{name}
      #{full_name}.text = text
      if block_given?
        yield #{full_name}
      else
        #{full_name}
      end
    end
  EOC
end

#def_explicit_clean_other_accessor(klass, full_name) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/rss/maker/itunes.rb', line 46

def def_explicit_clean_other_accessor(klass, full_name)
  klass.def_other_element(full_name)
  klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
    def #{full_name}?
      Utils::ExplicitCleanOther.parse(#{full_name})
    end
  EOC
end

#def_yes_other_accessor(klass, full_name) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/rss/maker/itunes.rb', line 37

def def_yes_other_accessor(klass, full_name)
  klass.def_other_element(full_name)
  klass.module_eval(<<-EOC, __FILE__, __LINE__ + 1)
    def #{full_name}?
      Utils::YesOther.parse(@#{full_name})
    end
  EOC
end