Class: McBlocky::DSL::Selector
- Inherits:
-
Object
- Object
- McBlocky::DSL::Selector
- Defined in:
- lib/mcblocky/dsl/selector.rb
Instance Method Summary collapse
- #[](**args) ⇒ Object
-
#initialize(name, **kwargs) ⇒ Selector
constructor
A new instance of Selector.
- #to_s ⇒ Object
Constructor Details
#initialize(name, **kwargs) ⇒ Selector
Returns a new instance of Selector.
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/mcblocky/dsl/selector.rb', line 3 def initialize(name, **kwargs) @name = name if kwargs[:loc] loc = kwargs[:loc] raise ArgumentError, "Relative locations are not allowed in selectors" if loc.is_relative? kwargs[:x] = loc.x kwargs[:y] = loc.y kwargs[:z] = loc.z kwargs.delete :loc end @args = kwargs end |
Instance Method Details
#[](**args) ⇒ Object
16 17 18 |
# File 'lib/mcblocky/dsl/selector.rb', line 16 def [](**args) Selector.new(@name, @args.merge(args)) end |
#to_s ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/mcblocky/dsl/selector.rb', line 20 def to_s if @args.empty? @name else pairs = @args.map{|k,v| "#{k}=#{v}"} "#{@name}[#{pairs.join(',')}]" end end |