Sha256: b5479cd54a3fe64be2638a6c695dbc00238fa5e6d6770a3cea8727e33c39ac8e
Contents?: true
Size: 1.15 KB
Versions: 3
Compression:
Stored size: 1.15 KB
Contents
module ActiveText # These are currently the kinds of metadata that we can fetch # This should be configurable in the future (or remove it entirely) METADATA = %w(name kind description) class Variable attr_reader :key, :context, :comment 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 # if any of the metadata string methods are called # then we return what the value is def method_missing(method_name) if METADATA.include? method_name.to_s content_of(method_name.to_s) end end def value @context.split("\n").each do |string| string =~ /^\${1}#{@key}: (.+);/ return $1 if $1 end end def value=(val) @context.gsub!(/^\$#{@key}: .+;/, "$#{@key}: #{val};") end private def content_of(metadata) @context.split("\n").each do |string| string =~ /^#{@comment} @([\w]+[^\s]) (.+)/ return $2 if $1 == metadata end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
active_text-0.1.5 | lib/active_text/variable.rb |
active_text-0.1.1 | lib/active_text/variable.rb |
active_text-0.1.0 | lib/active_text/variable.rb |