Class: DotUsage::DotUsageFile

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

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ DotUsageFile

Returns a new instance of DotUsageFile.



9
10
11
12
# File 'lib/dot_usage.rb', line 9

def initialize(filename)
  @filename = filename
  @data = YAML.load_file filename
end

Instance Method Details

#recipe(target) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dot_usage.rb', line 18

def recipe(target)
  content = @data[target]

  if content.instance_of? Array
    content
  elsif content.instance_of? String
    [content]
  elsif content.instance_of? Hash
    unless 1 == content.length
      STDERR.puts content
      STDERR.puts 'Error: hash may only have one entry!'
      return 1
    end

    md = MarkdownFile.new content.keys.first

    md.snippet content.values.first
  else
    STDERR.puts content
    STDERR.puts 'Error: invalid recipe!'
    1
  end
end

#targetsObject



14
15
16
# File 'lib/dot_usage.rb', line 14

def targets
  @data.keys
end