Class: Ruby2JS::Line

Inherits:
Array
  • Object
show all
Defined in:
lib/ruby2js/serializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#indentObject

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

Returns:

  • (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

Returns:

  • (Boolean)


26
27
28
# File 'lib/ruby2js/serializer.rb', line 26

def empty?
  all? {|line| line.empty?}
end

#to_sObject



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