Class: Template

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Template

Returns a new instance of Template.



6
7
8
9
10
11
# File 'lib/things_templates/template.rb', line 6

def initialize(file)
  yaml = YAML.load(File.open(file))
  @items = yaml['items']
  @project = yaml.fetch('project', nil)
  @tags = yaml.fetch('tags', nil)
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



4
5
6
# File 'lib/things_templates/template.rb', line 4

def items
  @items
end

#projectObject (readonly)

Returns the value of attribute project.



4
5
6
# File 'lib/things_templates/template.rb', line 4

def project
  @project
end

#tagsObject (readonly)

Returns the value of attribute tags.



4
5
6
# File 'lib/things_templates/template.rb', line 4

def tags
  @tags
end

Instance Method Details

#build!Object



13
14
15
16
17
18
19
20
21
# File 'lib/things_templates/template.rb', line 13

def build!
  if project
    ThingsController.add_items_to_project(project, items, tags)
  else
    items.each do |item|
      ThingsController.add_item(item)
    end
  end
end