Class: Ting::Converter

Inherits:
Object
  • Object
show all
Includes:
Procable
Defined in:
lib/ting/converter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Procable

#memoize, #to_proc

Constructor Details

#initialize(from, from_tone, to, to_tone) ⇒ Converter

Returns a new instance of Converter.



7
8
9
# File 'lib/ting/converter.rb', line 7

def initialize(from, from_tone, to, to_tone)
  @from_conv, @from_tone, @to_conv, @to_tone = from, from_tone, to, to_tone
end

Instance Attribute Details

#from_convObject (readonly)

Returns the value of attribute from_conv.



5
6
7
# File 'lib/ting/converter.rb', line 5

def from_conv
  @from_conv
end

#from_toneObject (readonly)

Returns the value of attribute from_tone.



5
6
7
# File 'lib/ting/converter.rb', line 5

def from_tone
  @from_tone
end

#to_convObject (readonly)

Returns the value of attribute to_conv.



5
6
7
# File 'lib/ting/converter.rb', line 5

def to_conv
  @to_conv
end

#to_toneObject (readonly)

Returns the value of attribute to_tone.



5
6
7
# File 'lib/ting/converter.rb', line 5

def to_tone
  @to_tone
end

Instance Method Details

#convert(str) ⇒ Object Also known as: <<, call



19
20
21
# File 'lib/ting/converter.rb', line 19

def convert(str)
  writer.unparse reader.parse(str)
end

#readerObject



11
12
13
# File 'lib/ting/converter.rb', line 11

def reader
  @reader ||= Reader.new(from_conv, from_tone)
end

#to(to, to_tone) ⇒ Object



23
24
25
# File 'lib/ting/converter.rb', line 23

def to(to, to_tone)
  Converter.new(self.from_conv, self.from_tone, to, to_tone)
end

#writerObject



15
16
17
# File 'lib/ting/converter.rb', line 15

def writer
  @writer ||= Writer.new(to_conv, to_tone)
end