Class: ActiveText::Variable
- Inherits:
-
Object
- Object
- ActiveText::Variable
- Defined in:
- lib/active_text/variable.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key, context, comment) ⇒ Variable
constructor
A new instance of Variable.
-
#method_missing(method_name) ⇒ Object
if any of the metadata string methods are called then we return what the value is.
- #value ⇒ Object
- #value=(val) ⇒ Object
Constructor Details
#initialize(key, context, comment) ⇒ Variable
Returns a new instance of Variable.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/active_text/variable.rb', line 9 def initialize(key, context, comment) # What the short name of this variable is @key = key # Text surrounding the variable, as determined by Base @context = context # What is considered a comment @comment = comment end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
if any of the metadata string methods are called then we return what the value is
22 23 24 25 26 |
# File 'lib/active_text/variable.rb', line 22 def method_missing(method_name) if METADATA.include? method_name.to_s content_of(method_name.to_s) end end |
Instance Attribute Details
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
7 8 9 |
# File 'lib/active_text/variable.rb', line 7 def comment @comment end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/active_text/variable.rb', line 7 def context @context end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
7 8 9 |
# File 'lib/active_text/variable.rb', line 7 def key @key end |
Instance Method Details
#value ⇒ Object
28 29 30 31 32 33 |
# File 'lib/active_text/variable.rb', line 28 def value @context.split("\n").each do |string| string =~ /^\${1}#{@key}: (.+);/ return $1 if $1 end end |
#value=(val) ⇒ Object
35 36 37 |
# File 'lib/active_text/variable.rb', line 35 def value=(val) @context.gsub!(/^\$#{@key}: .+;/, "$#{@key}: #{val};") end |