Class: Glaemscribe::API::Option
Defined Under Namespace
Classes: Type
Instance Attribute Summary collapse
-
#default_value_name ⇒ Object
readonly
Returns the value of attribute default_value_name.
-
#is_radio ⇒ Object
Returns the value of attribute is_radio.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #default_value ⇒ Object
-
#initialize(mode, name, default_value_name, values, line, visibility = nil) ⇒ Option
constructor
A new instance of Option.
- #value_for_value_name(val_name) ⇒ Object
- #value_name_for_value(value) ⇒ Object
- #visible? ⇒ Boolean
Constructor Details
#initialize(mode, name, default_value_name, values, line, visibility = nil) ⇒ Option
Returns a new instance of Option.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/api/option.rb', line 41 def initialize(mode, name, default_value_name, values, line, visibility = nil) @mode = mode @name = name @default_value_name = default_value_name @type = (values.keys.count == 0)?(Type::BOOL):(Type::ENUM) @values = values @visibility = visibility @line = line @value_to_names = {} @values.each { |vname, val| @value_to_names[val] = vname } end |
Instance Attribute Details
#default_value_name ⇒ Object (readonly)
Returns the value of attribute default_value_name.
31 32 33 |
# File 'lib/api/option.rb', line 31 def default_value_name @default_value_name end |
#is_radio ⇒ Object
Returns the value of attribute is_radio.
34 35 36 |
# File 'lib/api/option.rb', line 34 def is_radio @is_radio end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
28 29 30 |
# File 'lib/api/option.rb', line 28 def line @line end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
27 28 29 |
# File 'lib/api/option.rb', line 27 def mode @mode end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
29 30 31 |
# File 'lib/api/option.rb', line 29 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
30 31 32 |
# File 'lib/api/option.rb', line 30 def type @type end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
32 33 34 |
# File 'lib/api/option.rb', line 32 def values @values end |
Instance Method Details
#default_value ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/api/option.rb', line 53 def default_value if @type == Type::BOOL (@default_value_name == 'true') else @values[@default_value_name] end end |
#value_for_value_name(val_name) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/api/option.rb', line 61 def value_for_value_name(val_name) if @type == Type::BOOL return true if(val_name == 'true' || val_name == true) return false if(val_name == 'false' || val_name == false) return nil else return @values[val_name] end end |
#value_name_for_value(value) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/api/option.rb', line 71 def value_name_for_value(value) if @type == Type::BOOL return "true" if value == true || value == "true" return "false" if value == false || value == "false" return nil else return @value_to_names[value] end end |
#visible? ⇒ Boolean
81 82 83 84 85 86 87 88 89 |
# File 'lib/api/option.rb', line 81 def visible? if_eval = Eval::Parser.new() begin (if_eval.parse(@visibility || "true", @mode.latest_option_values || {}) == true) rescue Eval::IfEvalError => e nil end end |