Class: Glaemscribe::API::SheafChain
Constant Summary collapse
- SHEAF_REGEXP_IN =
/\[(.*?)\]/
- SHEAF_REGEXP_OUT =
/(\[.*?\])/
Instance Attribute Summary collapse
-
#expression ⇒ Object
readonly
Returns the value of attribute expression.
-
#is_src ⇒ Object
readonly
Returns the value of attribute is_src.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
-
#sheaves ⇒ Object
readonly
Returns the value of attribute sheaves.
Instance Method Summary collapse
- #dst? ⇒ Boolean
-
#initialize(rule, expression, is_src) ⇒ SheafChain
constructor
Pass in the whole member of a rule src => dst (src or dst).
- #p ⇒ Object
- #src? ⇒ Boolean
Constructor Details
#initialize(rule, expression, is_src) ⇒ SheafChain
Pass in the whole member of a rule src => dst (src or dst)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/api/sheaf_chain.rb', line 58 def initialize(rule, expression, is_src) @rule = rule @mode = rule.mode @is_src = is_src @expression = expression # Split expression with '[...]' patterns. e.g. 'b[a*c*d]e' => [b, a*c*d, e] sheaf_exps = expression.split(SHEAF_REGEXP_OUT).map{ |elt| elt.strip }.reject{ |elt| elt.empty? } sheaf_exps = sheaf_exps.map { |sheaf_exp| sheaf_exp =~ SHEAF_REGEXP_IN linkable = false if $1 # Take the interior of the brackets it was a [...] expression sheaf_exp = $1 linkable = true end { exp: sheaf_exp.strip, linkable: linkable } } @sheaves = sheaf_exps.map{ |sd| Sheaf.new(self, sd[:exp], sd[:linkable]) } @sheaves = [Sheaf.new(self,"",false)] if @sheaves.empty? end |
Instance Attribute Details
#expression ⇒ Object (readonly)
Returns the value of attribute expression.
52 53 54 |
# File 'lib/api/sheaf_chain.rb', line 52 def expression @expression end |
#is_src ⇒ Object (readonly)
Returns the value of attribute is_src.
47 48 49 |
# File 'lib/api/sheaf_chain.rb', line 47 def is_src @is_src end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
49 50 51 |
# File 'lib/api/sheaf_chain.rb', line 49 def mode @mode end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
50 51 52 |
# File 'lib/api/sheaf_chain.rb', line 50 def rule @rule end |
#sheaves ⇒ Object (readonly)
Returns the value of attribute sheaves.
48 49 50 |
# File 'lib/api/sheaf_chain.rb', line 48 def sheaves @sheaves end |
Instance Method Details
#dst? ⇒ Boolean
55 |
# File 'lib/api/sheaf_chain.rb', line 55 def dst? ; !is_src ; end |
#p ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/api/sheaf_chain.rb', line 80 def p ret = ("*" * 30) ret += "\n" ret += @expression + "\n" @sheaves.each{ |s| ret += s.p } ret end |
#src? ⇒ Boolean
54 |
# File 'lib/api/sheaf_chain.rb', line 54 def src? ; is_src ; end |