lib/kaiser_ruby/rockstar_transform.rb in kaiser-ruby-0.5 vs lib/kaiser_ruby/rockstar_transform.rb in kaiser-ruby-0.5.1
- old
+ new
@@ -31,14 +31,14 @@
rule(numeric_value: simple(:num)) { num }
rule(unquoted_string: simple(:str)) { "\"#{str}\"" }
rule(string_as_number: simple(:str)) do |context|
if context[:str].to_s.include?('.')
context[:str].to_s.gsub(/[^A-Za-z\s\.]/, '').split('.').map do |sub|
- str_to_num(sub)
+ str_to_num(sub.strip)
end.join('.').to_f
else
- str_to_num(context[:str])
+ str_to_num(context[:str]).to_i
end
end
rule(assignment: { left: simple(:left), right: simple(:right) }) { "#{left} = #{right}" }
rule(increment: simple(:str)) { "#{str} += 1" }
@@ -216,9 +216,9 @@
def self.parameterize(string)
string.to_s.downcase.gsub(/\s+/, '_')
end
def self.str_to_num(string)
- string.to_s.split(/\s+/).map { |e| e.length % 10 }.join.to_i
+ string.to_s.split(/\s+/).map { |e| e.length % 10 }.join
end
end
end