class Interscript::Node::Item::Any
Attributes
value[RW]
Public Class Methods
new(data)
click to toggle source
# File lib/interscript/node/item/any.rb, line 3 def initialize data case data when Array, ::String, Range self.value = data when Interscript::Node::Item::Group # debug alalc-ara-Arab-Latn-1997 line 683 self.value = data.children when Interscript::Node::Item::Alias # debug mofa-jpn-Hrkt-Latn-1989 line 116 self.value = Interscript::Stdlib::ALIASES[data.name] else puts data.inspect raise TypeError, "Wrong type #{data[0].class}, excepted Array, String or Range" end end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
Interscript::Node::Item#==
# File lib/interscript/node/item/any.rb, line 76 def ==(other) super && self.data == other.data end
data()
click to toggle source
# File lib/interscript/node/item/any.rb, line 17 def data case @value when Array value.map { |i| Interscript::Node::Item.try_convert(i) } when ::String value.split("").map { |i| Interscript::Node::Item.try_convert(i) } when Range value.map { |i| Interscript::Node::Item.try_convert(i) } end end
downcase()
click to toggle source
# File lib/interscript/node/item/any.rb, line 28 def downcase; self.class.new(self.data.map(&:downcase)); end
first_string()
click to toggle source
# File lib/interscript/node/item/any.rb, line 31 def first_string case @value when Array Interscript::Node::Item.try_convert(value.first).first_string when ::String value[0] when Range value.begin end end
inspect()
click to toggle source
# File lib/interscript/node/item/any.rb, line 80 def inspect "any(#{value.inspect})" end
max_length()
click to toggle source
# File lib/interscript/node/item/any.rb, line 52 def max_length self.data.map(&:max_length).max end
nth_string()
click to toggle source
# File lib/interscript/node/item/any.rb, line 42 def nth_string return first_string unless $select_nth_string d = data Fiber.yield(:prepare) id = Fiber.yield(:select_nth_string, d.count, self.hash) Fiber.yield(:selection) Interscript::Node::Item.try_convert(value[id]).nth_string end
to_hash()
click to toggle source
# File lib/interscript/node/item/any.rb, line 56 def to_hash hash = { :class => self.class.to_s } case @value when Array hash[:type] = "Array" hash[:data] = data.map { |i| i.to_hash } when ::String hash[:type] = "String" hash[:data] = @value when Range hash[:type] = "Range" hash[:data] = [@value.begin, @value.end] when NilClass hash[:type] = "nil (bug)" end hash end
to_html(doc)
click to toggle source
# File lib/interscript/visualize/nodes.rb, line 25 def to_html(doc) "<nobr>any (</nobr>" + case @value when Array value.map(&Interscript::Node::Item.method(:try_convert)).map{|i|i.to_html(doc)}.join(", ") when ::String value.split("").map(&Interscript::Node::Item.method(:try_convert)).map{|i|i.to_html(doc)}.join(", ") when Range [value.begin, value.end].map(&Interscript::Node::Item.method(:try_convert)).map{|i|i.to_html(doc)}.join(" to ") else h(value.inspect) end + ")" end
upcase()
click to toggle source
# File lib/interscript/node/item/any.rb, line 29 def upcase; self.class.new(self.data.map(&:upcase)); end