Class: SentenceBuilder::SentenceNode
- Defined in:
- lib/sentence_builder/sentence_node.rb
Instance Attribute Summary collapse
-
#custom_structure ⇒ Object
readonly
Returns the value of attribute custom_structure.
-
#custom_structure_hash ⇒ Object
readonly
Returns the value of attribute custom_structure_hash.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sort_by_value ⇒ Object
readonly
Returns the value of attribute sort_by_value.
Attributes inherited from BaseNode
Instance Method Summary collapse
- #always_use ⇒ Object
- #always_use=(new_value) ⇒ Object
- #display_name ⇒ Object
- #display_name=(new_display_name) ⇒ Object
- #extra ⇒ Object
-
#initialize(name, options = {}) ⇒ SentenceNode
constructor
A new instance of SentenceNode.
-
#match_with_options ⇒ Object
If this is true and options is a hash with format 123, value: 456, xxx: 789 Then default option entered as the value in hash gets converted into its name.
- #match_with_options=(new_value) ⇒ Object
- #options ⇒ Object
- #options=(new_options) ⇒ Object
- #structure(value = nil) ⇒ Object
- #to_hash(current_value = nil) ⇒ Object
- #type ⇒ Object
- #type=(new_type) ⇒ Object
Methods inherited from BaseNode
#prefix, #prefix=, #suffix, #suffix=
Constructor Details
#initialize(name, options = {}) ⇒ SentenceNode
Returns a new instance of SentenceNode.
10 11 12 13 14 15 16 |
# File 'lib/sentence_builder/sentence_node.rb', line 10 def initialize(name, = {}) super(name, ) = @sort_by_value = [:sort_by_value].to_i @custom_structure = [:custom_structure] || nil @custom_structure_hash = [:custom_structure_hash] || {} end |
Instance Attribute Details
#custom_structure ⇒ Object (readonly)
Returns the value of attribute custom_structure.
8 9 10 |
# File 'lib/sentence_builder/sentence_node.rb', line 8 def custom_structure @custom_structure end |
#custom_structure_hash ⇒ Object (readonly)
Returns the value of attribute custom_structure_hash.
8 9 10 |
# File 'lib/sentence_builder/sentence_node.rb', line 8 def custom_structure_hash @custom_structure_hash end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/sentence_builder/sentence_node.rb', line 8 def name @name end |
#sort_by_value ⇒ Object (readonly)
Returns the value of attribute sort_by_value.
8 9 10 |
# File 'lib/sentence_builder/sentence_node.rb', line 8 def sort_by_value @sort_by_value end |
Instance Method Details
#always_use ⇒ Object
28 29 30 |
# File 'lib/sentence_builder/sentence_node.rb', line 28 def always_use SentenceBuilder::Helper.is_boolean([:always_use]) ? [:always_use] : true end |
#always_use=(new_value) ⇒ Object
32 33 34 |
# File 'lib/sentence_builder/sentence_node.rb', line 32 def always_use=(new_value) [:always_use] = SentenceBuilder::Helper.to_boolean(new_value) end |
#display_name ⇒ Object
36 37 38 |
# File 'lib/sentence_builder/sentence_node.rb', line 36 def display_name [:display_name] || nil end |
#display_name=(new_display_name) ⇒ Object
40 41 42 |
# File 'lib/sentence_builder/sentence_node.rb', line 40 def display_name=(new_display_name) [:display_name] = new_display_name || nil end |
#extra ⇒ Object
60 61 62 |
# File 'lib/sentence_builder/sentence_node.rb', line 60 def extra [:extra] || [] end |
#match_with_options ⇒ Object
If this is true and options is a hash with format 123, value: 456, xxx: 789 Then default option entered as the value in hash gets converted into its name
20 21 22 |
# File 'lib/sentence_builder/sentence_node.rb', line 20 def SentenceBuilder::Helper.is_boolean([:match_with_options]) ? [:match_with_options] : false end |
#match_with_options=(new_value) ⇒ Object
24 25 26 |
# File 'lib/sentence_builder/sentence_node.rb', line 24 def (new_value) [:match_with_options] = SentenceBuilder::Helper.to_boolean(new_value) end |
#options ⇒ Object
44 45 46 |
# File 'lib/sentence_builder/sentence_node.rb', line 44 def [:options] || [] end |
#options=(new_options) ⇒ Object
48 49 50 |
# File 'lib/sentence_builder/sentence_node.rb', line 48 def () [:options] = || [] end |
#structure(value = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/sentence_builder/sentence_node.rb', line 83 def structure(value = nil) if value.present? names = get_option_names(value) if and names.present? add_prefix_and_suffix(enhance_content(names)) else add_prefix_and_suffix(enhance_content(value)) end elsif @default.present? names = get_option_names(@default) if and names.present? add_prefix_and_suffix(enhance_content(names)) else add_prefix_and_suffix(enhance_content(@default)) end elsif @custom_structure.present? and @custom_structure.is_a?(String) @custom_structure % {sb_prefix: prefix, sb_suffix: suffix}.merge(@custom_structure_hash) else '' end end |
#to_hash(current_value = nil) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/sentence_builder/sentence_node.rb', line 64 def to_hash(current_value = nil) { name: @name, type: type, always_use: always_use, display_name: display_name, default: @default, prefix: prefix, suffix: suffix, current_value: current_value, options: , extra: @extra, sort_by_value: @sort_by_value, custom_structure: @custom_structure, custom_structure_hash: @custom_structure_hash, sentence: structure(current_value) } end |
#type ⇒ Object
52 53 54 |
# File 'lib/sentence_builder/sentence_node.rb', line 52 def type [:type] || 'custom' end |
#type=(new_type) ⇒ Object
56 57 58 |
# File 'lib/sentence_builder/sentence_node.rb', line 56 def type=(new_type) [:type] = new_type || 'custom' end |