Class: Cubicle::Member

Inherits:
Object
  • Object
show all
Defined in:
lib/cubicle/member.rb

Direct Known Subclasses

Dimension, Expansion, Measure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Member

Returns a new instance of Member.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cubicle/member.rb', line 12

def initialize(*args)
  opts = args.extract_options!
  @name = args.shift.to_sym if args[0].is_a?(String) or args[0].is_a?(Symbol)

  self.options = (opts || {}).symbolize_keys

  if @expression = options(:field_name)
    @expression_type = :field_name
    @field_name = @expression
  elsif @expression = options(:expression)
    @expression_type = :javascript
  else
    @expression = @name
    @field_name = @name
    @expression_type = :field_name
  end

  member_alias = options(:alias)
  if (member_alias)
    member_alias = [member_alias] unless member_alias.is_a?(Array)
    @alias_list = member_alias.map{|a|a.to_s}
  end

  @condition = options :condition_expression,:condition


end

Instance Attribute Details

#alias_list ⇒ Object

Returns the value of attribute alias_list.



4
5
6
# File 'lib/cubicle/member.rb', line 4

def alias_list
  @alias_list
end

#condition ⇒ Object

Returns the value of attribute condition.



4
5
6
# File 'lib/cubicle/member.rb', line 4

def condition
  @condition
end

#expression ⇒ Object

Returns the value of attribute expression.



4
5
6
# File 'lib/cubicle/member.rb', line 4

def expression
  @expression
end

#expression_type ⇒ Object

Returns the value of attribute expression_type.



4
5
6
# File 'lib/cubicle/member.rb', line 4

def expression_type
  @expression_type
end

#field_name ⇒ Object

Returns the value of attribute field_name.



4
5
6
# File 'lib/cubicle/member.rb', line 4

def field_name
  @field_name
end

#name ⇒ Object

Returns the value of attribute name.



4
5
6
# File 'lib/cubicle/member.rb', line 4

def name
  @name
end

#options(*args) ⇒ Object

Returns the value of attribute options.



4
5
6
# File 'lib/cubicle/member.rb', line 4

def options
  @options
end

Instance Method Details

#included_in?(list_of_member_names) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
52
53
54
# File 'lib/cubicle/member.rb', line 49

def included_in?(list_of_member_names)
  list_of_member_names.each do |member_name|
    return true if matches(member_name)
  end
  false
end

#matches(member_name) ⇒ Object



45
46
47
# File 'lib/cubicle/member.rb', line 45

def matches(member_name)
  return name.to_s == member_name.to_s || (@alias_list||=[]).include?(member_name.to_s)
end

#to_js_keys ⇒ Object



56
57
58
# File 'lib/cubicle/member.rb', line 56

def to_js_keys
  ["#{name}:#{to_js_value}"]
end

#to_js_value ⇒ Object



65
66
67
# File 'lib/cubicle/member.rb', line 65

def to_js_value
  condition.blank? ? expression : "(#{condition}) ? (#{expression}) : null"
end