Class: ToLua::Generator::State

Inherits:
Object
  • Object
show all
Defined in:
lib/to_lua/generator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ State

Returns a new instance of State.



21
22
23
24
25
26
# File 'lib/to_lua/generator.rb', line 21

def initialize(opts = {})
  @pretty = false
  @depth  = 0
  @indent = '  '
  configure(opts)
end

Instance Attribute Details

#depthObject

Returns the value of attribute depth.



6
7
8
# File 'lib/to_lua/generator.rb', line 6

def depth
  @depth
end

#indentObject

Returns the value of attribute indent.



6
7
8
# File 'lib/to_lua/generator.rb', line 6

def indent
  @indent
end

Class Method Details

.from_state(opts) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/to_lua/generator.rb', line 8

def self.from_state(opts)
  case
  when self === opts
    opts
  when opts.respond_to?(:to_hash)
    new(opts.to_hash)
  when opts.respond_to?(:to_h)
    new(opts.to_h)
  else
    new
  end
end

Instance Method Details

#==(other) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/to_lua/generator.rb', line 45

def ==(other)
  if other.is_a? State
    self.to_h == other.to_h
  else
    false
  end
end

#configure(opts) ⇒ Object



28
29
30
31
# File 'lib/to_lua/generator.rb', line 28

def configure(opts)
  @pretty = opts[:pretty] if opts.key?(:pretty)
  @indent = opts[:indent] if opts.key?(:indent)
end

#pretty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/to_lua/generator.rb', line 33

def pretty?
  @pretty
end

#to_hObject



37
38
39
40
41
42
43
# File 'lib/to_lua/generator.rb', line 37

def to_h
  {
    pretty: @pretty,
    indent: @indent,
    depth:  @depth
  }
end