Class: Apfel::ParsedDotStrings
- Inherits:
-
Object
- Object
- Apfel::ParsedDotStrings
- Defined in:
- lib/apfel/parsed_dot_strings.rb
Instance Attribute Summary collapse
-
#kv_pairs ⇒ Object
Returns the value of attribute kv_pairs.
Instance Method Summary collapse
- #comments(args = {}) ⇒ Object
-
#initialize ⇒ ParsedDotStrings
constructor
A new instance of ParsedDotStrings.
- #key_values ⇒ Object
- #keys ⇒ Object
- #to_hash(args = {}) ⇒ Object
- #to_json(args = {}) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize ⇒ ParsedDotStrings
Returns a new instance of ParsedDotStrings.
6 7 8 |
# File 'lib/apfel/parsed_dot_strings.rb', line 6 def initialize @kv_pairs = [] end |
Instance Attribute Details
#kv_pairs ⇒ Object
Returns the value of attribute kv_pairs.
4 5 6 |
# File 'lib/apfel/parsed_dot_strings.rb', line 4 def kv_pairs @kv_pairs end |
Instance Method Details
#comments(args = {}) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/apfel/parsed_dot_strings.rb', line 28 def comments(args={}) with_keys = args[:with_keys].nil? ? true : args[:with_keys] cleaned_pairs = kv_pairs.map do |pair| pair end with_keys ? build_comment_hash(cleaned_pairs) : cleaned_pairs.map(&:comment) end |
#key_values ⇒ Object
10 11 12 13 14 |
# File 'lib/apfel/parsed_dot_strings.rb', line 10 def key_values kv_pairs.map do |pair| {pair.key => pair.value} end end |
#keys ⇒ Object
16 17 18 19 20 |
# File 'lib/apfel/parsed_dot_strings.rb', line 16 def keys kv_pairs.map do |pair| pair.key end end |
#to_hash(args = {}) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/apfel/parsed_dot_strings.rb', line 36 def to_hash(args={}) with_comments = args[:with_comments].nil? ? true : args[:with_comments] build_hash { |hash, pair| hash_value = with_comments ? { pair.value => pair.comment } : pair.value hash[pair.key] = hash_value } end |
#to_json(args = {}) ⇒ Object
45 46 47 |
# File 'lib/apfel/parsed_dot_strings.rb', line 45 def to_json(args={}) self.to_hash(with_comments: args[:with_comments]).to_json end |
#values ⇒ Object
22 23 24 25 26 |
# File 'lib/apfel/parsed_dot_strings.rb', line 22 def values kv_pairs.map do |pair| pair.value end end |