Class: XDry::SynthesizeItem

Inherits:
Object
  • Object
show all
Defined in:
lib/xdry/parsing/nodes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(property_name, field_name = nil) ⇒ SynthesizeItem

Returns a new instance of SynthesizeItem.



152
153
154
# File 'lib/xdry/parsing/nodes.rb', line 152

def initialize property_name, field_name = nil
  @property_name, @field_name = property_name, field_name
end

Instance Attribute Details

#field_nameObject (readonly)

Returns the value of attribute field_name.



150
151
152
# File 'lib/xdry/parsing/nodes.rb', line 150

def field_name
  @field_name
end

#property_nameObject (readonly)

Returns the value of attribute property_name.



150
151
152
# File 'lib/xdry/parsing/nodes.rb', line 150

def property_name
  @property_name
end

Class Method Details

.parse(string) ⇒ Object



168
169
170
171
172
173
# File 'lib/xdry/parsing/nodes.rb', line 168

def self.parse string
  case string
    when /^(\w+)$/             then SynthesizeItem.new($1, nil)
    when /^(\w+)\s*=\s*(\w+)$/ then SynthesizeItem.new($1, $2)
  end
end

Instance Method Details

#has_field_name?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/xdry/parsing/nodes.rb', line 156

def has_field_name?
  not @field_name.nil?
end

#to_sObject



160
161
162
163
164
165
166
# File 'lib/xdry/parsing/nodes.rb', line 160

def to_s
  if has_field_name?
    "#{property_name}=#{field_name}"
  else
    "#{property_name}"
  end
end