Class: Writer::SymbolMatrix

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ SymbolMatrix

Returns a new instance of SymbolMatrix.



5
6
7
# File 'lib/writer/symbolmatrix.rb', line 5

def initialize source
  @source = source
end

Instance Attribute Details

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/writer/symbolmatrix.rb', line 3

def source
  @source
end

Instance Method Details

#hashObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/writer/symbolmatrix.rb', line 23

def hash
  the_hash = {}
  @source.each do |key, value|
    if value.respond_to? :to
      the_hash[key] = value.to.hash
    else
      the_hash[key] = value
    end
  end
  the_hash
end

#jsonObject



35
36
37
# File 'lib/writer/symbolmatrix.rb', line 35

def json
  @source.to_json
end

#serialization(prefix = nil) ⇒ Object Also known as: smas



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/writer/symbolmatrix.rb', line 9

def serialization prefix = nil
  result = ""
  @source.each do |key, value|
    unless value.is_a? Hash
      result += " #{prefix}#{key}:#{value}"
    else
      result += " " + Writer::SymbolMatrix.new(value).serialization("#{prefix}#{key}.")
    end
  end
  result[1..-1]
end

#string_key_hashObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/writer/symbolmatrix.rb', line 43

def string_key_hash 
  the_hash = {}
  @source.each do |key, value|
    if value.respond_to? :to
      the_hash[key.to_s] = value.to.string_key_hash
    else
      the_hash[key.to_s] = value
    end
  end
  the_hash
end

#yamlObject



39
40
41
# File 'lib/writer/symbolmatrix.rb', line 39

def yaml
  string_key_hash.to_yaml
end