Class: RubyToBlock::Block::Character

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

Overview

ソースコードに含まれるキャラクターを表現するクラス

Instance Attribute Summary collapse

Attributes inherited from Base

#fields, #parent, #prev_sibling, #sibling, #statements, #values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#[], #add_statement, #add_value, blocknize, indent?, #indent_level, inherited, inline?, #inline?, #null?, priority, process_else, process_end, process_value_string, regexp, statement?, #type, type, value?

Constructor Details

#initialize(options) ⇒ Character

Returns a new instance of Character.



28
29
30
31
32
33
34
35
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 28

def initialize(options)
  @name = options[:name]
  @costumes = options[:costumes]
  @x = options[:x]
  @y = options[:y]
  @angle = options[:angle]
  @rotation_style = options[:rotation_style]
end

Instance Attribute Details

#angleObject

Returns the value of attribute angle.



15
16
17
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 15

def angle
  @angle
end

#costumesObject

Returns the value of attribute costumes.



12
13
14
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 12

def costumes
  @costumes
end

#nameObject

rubocop:enable LineLength



11
12
13
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 11

def name
  @name
end

#rotation_styleObject

Returns the value of attribute rotation_style.



16
17
18
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 16

def rotation_style
  @rotation_style
end

#xObject

Returns the value of attribute x.



13
14
15
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 13

def x
  @x
end

#yObject

Returns the value of attribute y.



14
15
16
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 14

def y
  @y
end

Class Method Details

.process_match_data(md, context) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 18

def self.process_match_data(md, context)
  md2 = regexp.match(md[type])
  name = md2[1]
  context[:characters][name] = new(name: name, costumes: [md2[2]],
                                   x: md2[3], y: md2[4], angle: md2[5],
                                   rotation_style: md2[6] || 'free')

  true
end

Instance Method Details

#to_xml(parent) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/concerns/ruby_to_block/block/character.rb', line 37

def to_xml(parent)
  attrs = {
    'name' => @name,
    'x' => @x,
    'y' => @y,
    'angle' => @angle,
    'costumes' => @costumes.join(',')
  }
  attrs['rotation_style'] = @rotation_style if @rotation_style != 'free'
  parent.add_element('character', attrs)
end