Class: Ostructer::OsValue

Inherits:
OsBase show all
Includes:
Comparable
Defined in:
lib/ostructer.rb

Instance Attribute Summary

Attributes inherited from OsBase

#field, #logger, #parent

Instance Method Summary collapse

Methods inherited from OsBase

#full_dot_path

Constructor Details

#initialize(value, logger) ⇒ OsValue

holds/wraps a string



60
61
62
63
64
65
66
# File 'lib/ostructer.rb', line 60

def initialize( value, logger )
  @value   = value
  @logger  = logger
  
  @parent  = nil
  @field   ="[!unknown_value]"
end

Instance Method Details

#<=>(other) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/ostructer.rb', line 74

def <=>(other)
  if other.is_a? Numeric
    logger.debug "OsValue <=> Numeric:  #{self.to_i} <=> #{other}"
    self.to_i <=> other      
  elsif other.is_a? String
    logger.debug "OsValue <=> String:  #{self.to_s} <=> #{other}"
    self.to_s <=> other
  else
    logger.debug "OsValue - no <=> defined for type #{other.class}" 
    nil           
  end
  
  ## todo: add bool
end

#to_boolObject



97
98
99
# File 'lib/ostructer.rb', line 97

def to_bool
  @value == 'true'
end

#to_iObject



93
94
95
# File 'lib/ostructer.rb', line 93

def to_i
  @value.to_i
end

#to_openstruct_pass2Object



68
69
70
# File 'lib/ostructer.rb', line 68

def to_openstruct_pass2
  # do nothing (has no children)
end

#to_sObject



89
90
91
# File 'lib/ostructer.rb', line 89

def to_s
  @value
end