class TwitterCldr::Formatters::Rbnf::RuleParser

Private Instance Methods

add_and_advance(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 82
def add_and_advance(list)
  list << current_token
  next_token(current_token.type)
  switch(list)
end
close_bracket(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 74
def close_bracket(list)
  add_and_advance(list)
end
decimal(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 62
def decimal(list)
  add_and_advance(list)
end
descriptor(token) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 88
def descriptor(token)
  next_token(token.type)
  contents = []
  until current_token.type == token.type
    contents << current_token
    next_token(current_token.type)
  end
  contents
end
do_parse(options) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 14
def do_parse(options)
  @locale = options.fetch(:locale, TwitterCldr.locale)
  switch([])
end
equals(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 23
def equals(list)
  contents = descriptor(current_token)
  list << Substitution.new(:equals, contents, 2)
  next_token(:equals)
  switch(list)
end
left_arrow(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 30
def left_arrow(list)
  contents = descriptor(current_token)
  list << Substitution.new(:left_arrow, contents, 2)
  next_token(:left_arrow)
  switch(list)
end
open_bracket(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 70
def open_bracket(list)
  add_and_advance(list)
end
plaintext(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 66
def plaintext(list)
  add_and_advance(list)
end
plural(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 52
def plural(list)
  sub = Plural.from_string(
    @locale, current_token.value
  )

  list << sub
  next_token(:plural)
  switch(list)
end
right_arrow(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 37
def right_arrow(list)
  contents = descriptor(current_token)
  sub = Substitution.new(:right_arrow, contents, 2)
  next_token(:right_arrow)

  # handle >>> case
  if current_token.type == :right_arrow
    sub.length += 1
    next_token(:right_arrow)
  end

  list << sub
  switch(list)
end
semicolon(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 78
def semicolon(list)
  list
end
switch(list) click to toggle source
# File lib/twitter_cldr/formatters/numbers/rbnf/rule_parser.rb, line 19
def switch(list)
  send(current_token.type, list)
end