Class: Ruby2JS::Line
- Inherits:
-
Array
- Object
- Array
- Ruby2JS::Line
- Defined in:
- lib/ruby2js/serializer.rb
Instance Attribute Summary collapse
-
#indent ⇒ Object
Returns the value of attribute indent.
Instance Method Summary collapse
- #comment? ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize(*args) ⇒ Line
constructor
A new instance of Line.
- #to_s ⇒ Object
Constructor Details
#initialize(*args) ⇒ Line
Returns a new instance of Line.
16 17 18 19 |
# File 'lib/ruby2js/serializer.rb', line 16 def initialize(*args) super(args) @indent = 0 end |
Instance Attribute Details
#indent ⇒ Object
Returns the value of attribute indent.
14 15 16 |
# File 'lib/ruby2js/serializer.rb', line 14 def indent @indent end |
Instance Method Details
#comment? ⇒ Boolean
21 22 23 24 |
# File 'lib/ruby2js/serializer.rb', line 21 def comment? first = find {|token| !token.empty?} first and first.start_with? '//' end |
#empty? ⇒ Boolean
26 27 28 |
# File 'lib/ruby2js/serializer.rb', line 26 def empty? all? {|line| line.empty?} end |
#to_s ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ruby2js/serializer.rb', line 30 def to_s if empty? '' elsif ['case ', 'default:'].include? self[0] ' ' * ([0,indent-2].max) + join elsif indent > 0 ' ' * indent + join else join end end |