Class: Kbt::Template
- Inherits:
-
Object
- Object
- Kbt::Template
- Defined in:
- lib/kbt/template.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
- #file_content ⇒ Object
-
#initialize(file_path, key = nil) ⇒ Template
constructor
A new instance of Template.
- #keys ⇒ Object
- #value ⇒ Object
- #yml ⇒ Object
Constructor Details
#initialize(file_path, key = nil) ⇒ Template
Returns a new instance of Template.
5 6 7 8 |
# File 'lib/kbt/template.rb', line 5 def initialize(file_path, key = nil) @file_path = file_path.to_s =~ /.yml$/ ? file_path : "#{file_path}.yml" @key = key end |
Instance Attribute Details
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
4 5 6 |
# File 'lib/kbt/template.rb', line 4 def file_path @file_path end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
4 5 6 |
# File 'lib/kbt/template.rb', line 4 def key @key end |
Instance Method Details
#file_content ⇒ Object
14 15 16 |
# File 'lib/kbt/template.rb', line 14 def file_content @file_content ||= File.read(file_path) end |
#keys ⇒ Object
18 19 20 |
# File 'lib/kbt/template.rb', line 18 def keys key ? key.split('.') : nil end |
#value ⇒ Object
22 23 24 25 26 27 |
# File 'lib/kbt/template.rb', line 22 def value return yml unless keys keys.inject(yml) do |prev, nxt| prev[nxt] end end |
#yml ⇒ Object
10 11 12 |
# File 'lib/kbt/template.rb', line 10 def yml @yml ||= YAML.load(file_content) end |