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)



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/api/sheaf_chain.rb', line 56

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
    sheaf_exp = $1 if $1 # Take the interior of the brackets it was a [...] expression
    sheaf_exp.strip
  }
      
  @sheaves    = sheaf_exps.map{ |sheaf_exp| Sheaf.new(self,sheaf_exp) }
  @sheaves    = [Sheaf.new(self,"")] if @sheaves.empty?         
end

Instance Attribute Details

#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)


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

def dst? ; !is_src ; end

#pObject



74
75
76
77
78
79
80
81
82
# File 'lib/api/sheaf_chain.rb', line 74

def p
  ret = ("*" * 30) 
  ret += "\n"
  ret += @expression + "\n"
  @sheaves.each{ |s|
    ret += s.p
  }
  ret
end

#src?Boolean

Returns:

  • (Boolean)


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

def src? ; is_src ; end