Class: Safrano::Expand

Inherits:
ExpandBase show all
Defined in:
lib/odata/expand.rb

Overview

single expand

Constant Summary collapse

DEEPH_0 =

used for Sequel eager argument Recursive array to deep hash

1,2,3,4

–> 1=>{2=>{3=>4}}

1

–> 1

->(inp) { inp.size > 1 ? { inp[0] => DEEPH_0.call(inp[1..-1]) } : inp[0] }
DEEPH_1 =

used for building output template Recursive array to deep hash

1,2,3,4

–> 1=>{2=>{3=>4}}

1

–> { 1 => {} }

->(inp) { inp.size > 1 ? { inp[0] => DEEPH_1.call(inp[1..-1]) } : { inp[0] => {} } }
NODESEP =
'/'

Constants inherited from ExpandBase

Safrano::ExpandBase::EMPTYH, Safrano::ExpandBase::EmptyExpand

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ExpandBase

factory, #parse_error?

Constructor Details

#initialize(exstr) ⇒ Expand

Returns a new instance of Expand.



54
55
56
57
58
59
# File 'lib/odata/expand.rb', line 54

def initialize(exstr)
  exstr.strip!
  @expandp = exstr
  @nodes = @expandp.split(NODESEP)
  build_arg
end

Instance Attribute Details

#argObject (readonly)

sequel eager arg.



37
38
39
# File 'lib/odata/expand.rb', line 37

def arg
  @arg
end

#templateObject (readonly)

Returns the value of attribute template.



38
39
40
# File 'lib/odata/expand.rb', line 38

def template
  @template
end

Instance Method Details

#apply_to_dataset(dtcx) ⇒ Object



61
62
63
# File 'lib/odata/expand.rb', line 61

def apply_to_dataset(dtcx)
  Contract.valid(dtcx)
end

#build_argObject



65
66
67
68
69
70
# File 'lib/odata/expand.rb', line 65

def build_arg
  #   'a/b/c/d'  ==> {a: {b:{c: :d}}}
  #   'xy'  ==> :xy
  @arg = DEEPH_0.call(@nodes.map(&:to_sym))
  @template = DEEPH_1.call(@nodes)
end

#empty?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/odata/expand.rb', line 72

def empty?
  false
end