Module: Aska::InstanceMethods

Defined in:
lib/aska.rb

Instance Method Summary collapse

Instance Method Details

#__aska_aska(name) ⇒ Object



76
77
78
# File 'lib/aska.rb', line 76

def __aska_aska(name)
  self.class.aska_named(name)
end

#__aska_aska_stuff(m) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/aska.rb', line 52

def __aska_aska_stuff(m)
  if respond_to?(m.to_sym)
    self.send(m.to_sym)
  else
    m
  end
end

#__aska_get_var(name) ⇒ Object

Get the variable from the class If it’s defined as an attr_accessor, we know it has been defined as a rule Otherwise, if we are passing it as a



72
73
74
75
# File 'lib/aska.rb', line 72

def __aska_get_var(name)
  # attr_accessor?(name) ? aska(name) : 
  (supported_method?(name) ? name.to_sym : name.to_f)
end

#are_rules?(r) ⇒ Boolean

Returns:

  • (Boolean)


87
# File 'lib/aska.rb', line 87

def are_rules?(r);self.class.are_rules?(r);end

#attr_accessor?(name) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/aska.rb', line 79

def attr_accessor?(name)
  self.class.aska_attr_accessors.include?(name.to_sym)
end

#look_up_rules(r) ⇒ Object



86
# File 'lib/aska.rb', line 86

def look_up_rules(r);self.class.look_up_rules(r);end

#rulesObject



46
47
48
# File 'lib/aska.rb', line 46

def rules
  @rules ||= self.class.defined_rules
end

#supported_method?(meth) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/aska.rb', line 82

def supported_method?(meth)
  %w(< > == => =<).include?("#{meth}")
end

#valid_rule?(rule) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
62
63
64
65
66
67
68
# File 'lib/aska.rb', line 59

def valid_rule?(rule)
  rule.each do |key,value|
    begin
      # puts "#{aska(key)} #{value[0].to_sym} #{get_var(value[1])} (#{attr_accessor?(value[1])})"
      return __aska_aska_stuff(key).send(value[0].to_sym, __aska_get_var(value[1]))
    rescue Exception => e
      return false
    end
  end
end

#valid_rules?(name = :rules) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/aska.rb', line 49

def valid_rules?(name=:rules)
  self.class.look_up_rules(name).reject {|rule| valid_rule?(rule) }.empty?
end