Class: Apfel::ParsedDotStrings

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParsedDotStrings

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_pairsObject

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_valuesObject



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

#keysObject



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

#valuesObject



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