Class: Glaemscribe::API::SheafChain

Inherits:
Object
  • Object
show all
Defined in:
lib/api/sheaf_chain.rb

Constant Summary collapse

SHEAF_REGEXP_IN =
/\[(.*?)\]/
SHEAF_REGEXP_OUT =
/(\[.*?\])/

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#expressionObject (readonly)

Returns the value of attribute expression.



52
53
54
# File 'lib/api/sheaf_chain.rb', line 52

def expression
  @expression
end

#is_srcObject (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

#modeObject (readonly)

Returns the value of attribute mode.



49
50
51
# File 'lib/api/sheaf_chain.rb', line 49

def mode
  @mode
end

#ruleObject (readonly)

Returns the value of attribute rule.



50
51
52
# File 'lib/api/sheaf_chain.rb', line 50

def rule
  @rule
end

#sheavesObject (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

Returns:

  • (Boolean)


55
# File 'lib/api/sheaf_chain.rb', line 55

def dst? ; !is_src ; end

#pObject



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

Returns:

  • (Boolean)


54
# File 'lib/api/sheaf_chain.rb', line 54

def src? ; is_src ; end