Class: AjaxCat::Request::Phrase

Inherits:
Object
  • Object
show all
Defined in:
lib/ajax-cat/request/table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(words_list, alignment) ⇒ Phrase

Returns a new instance of Phrase.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ajax-cat/request/table.rb', line 65

def initialize(words_list, alignment)
	alignment = alignment.split("=")
	source_alignment = parse(alignment[0])
	target_alignment = parse(alignment[1])
	@from = source_alignment[:from]
	@to = source_alignment[:to]
	@words = ""
	target_alignment[:from].upto(target_alignment[:to]) do |position|
		@words += " #{words_list[position]}"
	end
	@words.strip!
end

Instance Attribute Details

#fromObject (readonly)

Returns the value of attribute from.



63
64
65
# File 'lib/ajax-cat/request/table.rb', line 63

def from
  @from
end

#toObject (readonly)

Returns the value of attribute to.



63
64
65
# File 'lib/ajax-cat/request/table.rb', line 63

def to
  @to
end

#wordsObject (readonly)

Returns the value of attribute words.



63
64
65
# File 'lib/ajax-cat/request/table.rb', line 63

def words
  @words
end

Instance Method Details

#parse(alignment) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ajax-cat/request/table.rb', line 78

def parse(alignment)
	if alignment.include?("-")
		alignment = alignment.split("-")
		from = alignment[0].to_i
		to = alignment[1].to_i
	else
		from = alignment.to_i
		to = from
	end
	return {from: from, to: to}
end