Class: SimpleFeed::Key::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/simplefeed/key/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace, key_types = DEFAULT_TYPES, text_template = DEFAULT_TEXT_TEMPLATE) ⇒ Template

Returns a new instance of Template.


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simplefeed/key/template.rb', line 22

def initialize(namespace,
               key_types = DEFAULT_TYPES,
               text_template = DEFAULT_TEXT_TEMPLATE
)

  self.namespace     = namespace
  self.key_types     = key_types
  self.text_template = text_template

  self.key_types.each do |type|
    type.template ||= text_template if text_template
  end
end

Instance Attribute Details

#key_typesObject

Returns the value of attribute key_types


20
21
22
# File 'lib/simplefeed/key/template.rb', line 20

def key_types
  @key_types
end

#namespaceObject

Returns the value of attribute namespace


20
21
22
# File 'lib/simplefeed/key/template.rb', line 20

def namespace
  @namespace
end

#text_templateObject

Returns the value of attribute text_template


20
21
22
# File 'lib/simplefeed/key/template.rb', line 20

def text_template
  @text_template
end

Instance Method Details

#key_namesObject

Returns array of key names, such as [:meta, :data]


43
44
45
# File 'lib/simplefeed/key/template.rb', line 43

def key_names
  key_types.map(&:name).map(&:to_s).sort
end

#render_optionsObject


36
37
38
39
40
# File 'lib/simplefeed/key/template.rb', line 36

def render_options
  h = {}
  h.merge!({ 'namespace' => namespace ? "#{namespace}|" : '' })
  h
end