Class: Writer::SymbolMatrix
- Inherits:
-
Object
- Object
- Writer::SymbolMatrix
- Defined in:
- lib/writer/symbolmatrix.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #hash ⇒ Object
-
#initialize(source) ⇒ SymbolMatrix
constructor
A new instance of SymbolMatrix.
- #json ⇒ Object
- #serialization(prefix = nil) ⇒ Object (also: #smas)
- #string_key_hash ⇒ Object
- #yaml ⇒ Object
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
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/writer/symbolmatrix.rb', line 3 def source @source end |
Instance Method Details
#hash ⇒ Object
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 |
#json ⇒ Object
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_hash ⇒ Object
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 |
#yaml ⇒ Object
39 40 41 |
# File 'lib/writer/symbolmatrix.rb', line 39 def yaml string_key_hash.to_yaml end |