Class: Weskit::WML::Item

Inherits:
Object show all
Includes:
Comparable, Mixins::Validator
Defined in:
lib/weskit/wml/item.rb

Direct Known Subclasses

Attribute, Element

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::Validator

raise_if_invalid, raise_if_missing, raise_unless

Constructor Details

#initialize(name, defaults = {}) ⇒ Item

Returns a new instance of Item.



20
21
22
23
# File 'lib/weskit/wml/item.rb', line 20

def initialize name, defaults = {}
  self.name = name
  merge defaults
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/weskit/wml/item.rb', line 5

def name
  @name
end

Class Method Details

.identifier(name) ⇒ Object



48
49
50
# File 'lib/weskit/wml/item.rb', line 48

def identifier name
  "#{name}".to_sym
end

Instance Method Details

#<=>(other) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/weskit/wml/item.rb', line 7

def <=> other
  case other
    when self.class then "#{name}" <=> "#{other.name}"
    when Item then "#{self.class}" <=> "#{other.class}"
    else nil
  end
end

#formatter=(item) ⇒ Object



15
16
17
18
# File 'lib/weskit/wml/item.rb', line 15

def formatter= item
  raise_unless Formatter, item
  @formatter = item
end

#merge(options = {}) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/weskit/wml/item.rb', line 25

def merge options = {}
  raise_unless Hash, options

  options.each do |option, value|
    raise_if_missing self, option
    send "#{option}=", value
  end

  self
end

#to_sObject Also known as: to_str



41
42
43
# File 'lib/weskit/wml/item.rb', line 41

def to_s
  formatter.format_detached self
end