Class: RubyToBlock::Block::Base

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/ruby_to_block.rb

Overview

すべてのブロックのベースクラス

Direct Known Subclasses

CharacterNew, EventsOnStart, Null, RubyStatement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



264
265
266
267
268
269
270
271
272
273
274
# File 'app/models/concerns/ruby_to_block.rb', line 264

def initialize(options = {})
  @fields = options[:fields] || {}
  @values = options[:values] || {}
  @statements = options[:statements] || {}

  if @statements.length > 0
    @statements.values.each do |s|
      s.parent = self
    end
  end
end

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields.



260
261
262
# File 'app/models/concerns/ruby_to_block.rb', line 260

def fields
  @fields
end

#parentObject

Returns the value of attribute parent.



258
259
260
# File 'app/models/concerns/ruby_to_block.rb', line 258

def parent
  @parent
end

#siblingObject

Returns the value of attribute sibling.



259
260
261
# File 'app/models/concerns/ruby_to_block.rb', line 259

def sibling
  @sibling
end

#statementsObject

Returns the value of attribute statements.



262
263
264
# File 'app/models/concerns/ruby_to_block.rb', line 262

def statements
  @statements
end

#valuesObject

Returns the value of attribute values.



261
262
263
# File 'app/models/concerns/ruby_to_block.rb', line 261

def values
  @values
end

Instance Method Details

#[](name) ⇒ Object



298
299
300
# File 'app/models/concerns/ruby_to_block.rb', line 298

def [](name)
  @fields[name]
end

#add_statement(name, block) ⇒ Object



302
303
304
305
306
# File 'app/models/concerns/ruby_to_block.rb', line 302

def add_statement(name, block)
  b = @statements[name]
  b = b.sibling while b.sibling
  b.sibling = block
end

#indent?Boolean

Returns:

  • (Boolean)


313
314
315
# File 'app/models/concerns/ruby_to_block.rb', line 313

def indent?
  false
end

#indent_levelObject



317
318
319
320
321
322
323
324
325
# File 'app/models/concerns/ruby_to_block.rb', line 317

def indent_level
  b = self
  level = 0
  while b.parent
    level += 1 if b.indent?
    b = b.parent
  end
  level
end

#inline?Boolean

Returns:

  • (Boolean)


290
291
292
# File 'app/models/concerns/ruby_to_block.rb', line 290

def inline?
  false
end

#null?Boolean

Returns:

  • (Boolean)


294
295
296
# File 'app/models/concerns/ruby_to_block.rb', line 294

def null?
  false
end

#to_xml(parent) ⇒ Object



276
277
278
279
280
281
282
283
284
# File 'app/models/concerns/ruby_to_block.rb', line 276

def to_xml(parent)
  e = parent.add_element('block', 'type' => type)
  e.add_attribute('inline', 'true') if inline?
  fields_to_xml(e)
  values_to_xml(e)
  statements_to_xml(e)
  sibling_to_xml(e)
  e
end

#typeObject



286
287
288
# File 'app/models/concerns/ruby_to_block.rb', line 286

def type
  @type ||= self.class.name.sub('RubyToBlock::Block::', '').underscore
end