Class: Savage::SubPath
- Inherits:
-
Object
- Object
- Savage::SubPath
- Includes:
- DirectionProxy, Utils
- Defined in:
- lib/savage/sub_path.rb
Instance Attribute Summary collapse
-
#directions ⇒ Object
Returns the value of attribute directions.
Instance Method Summary collapse
- #closed? ⇒ Boolean
- #commands ⇒ Object
-
#initialize(*args) {|_self| ... } ⇒ SubPath
constructor
A new instance of SubPath.
- #move_to(*args) ⇒ Object
- #to_command ⇒ Object
Methods included from DirectionProxy
Methods included from Utils
Constructor Details
#initialize(*args) {|_self| ... } ⇒ SubPath
Returns a new instance of SubPath.
21 22 23 24 25 |
# File 'lib/savage/sub_path.rb', line 21 def initialize(*args) @directions = [] move_to(*args) if (2..3).include?(args.length) yield self if block_given? end |
Instance Attribute Details
#directions ⇒ Object
Returns the value of attribute directions.
14 15 16 |
# File 'lib/savage/sub_path.rb', line 14 def directions @directions end |
Instance Method Details
#closed? ⇒ Boolean
45 46 47 |
# File 'lib/savage/sub_path.rb', line 45 def closed? @directions.last.kind_of? Directions::ClosePath end |
#commands ⇒ Object
41 42 43 |
# File 'lib/savage/sub_path.rb', line 41 def commands @directions end |
#move_to(*args) ⇒ Object
16 17 18 19 |
# File 'lib/savage/sub_path.rb', line 16 def move_to(*args) return nil unless @directions.empty? (@directions << Directions::MoveTo.new(*args)).last end |
#to_command ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/savage/sub_path.rb', line 27 def to_command @directions.to_enum(:each_with_index).collect { |dir, i| command_string = dir.to_command if i > 0 prev_command_code = @directions[i-1].command_code if dir.command_code == prev_command_code || (prev_command_code.match(/^[Mm]$/) && dir.command_code == 'L') command_string.gsub!(/^[A-Za-z]/,'') command_string.insert(0,' ') unless command_string.match(/^-/) end end command_string }.join end |