Class: QDA::Query::CodedByFunction

Inherits:
Function
  • Object
show all
Defined in:
lib/weft/query.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Function

#calculated?, #to_a

Constructor Details

#initialize(app, identifier) ⇒ CodedByFunction

Returns a new instance of CodedByFunction.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/weft/query.rb', line 75

def initialize(app, identifier)
  super(app)
  case identifier
  when Category # a category specified directly
    @identifier = identifier.dbid
  when String # a path to a category
    @identifier = app.get_category(identifier).dbid
  when Fixnum # a category id
    @identifier = identifier
  when NilClass
    raise ArgumentError.new("Unspecified category for CODED BY expression")
  else
    raise ArgumentError.new("Invalid value '#{identifier}' for CODED BY function")
  end
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



74
75
76
# File 'lib/weft/query.rb', line 74

def identifier
  @identifier
end

Instance Method Details

#calculateObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/weft/query.rb', line 96

def calculate()
  # TODO - Should raise NotFoundError?
  cat = @app.get_category(@identifier, false)
  raise NotFoundError if not cat

  @app.get_text_at_category( cat )
rescue NotFoundError => err
  raise CalculationError,
        "Could not retrieve category identified by #{@identifier}"
end

#to_sObject



91
92
93
94
# File 'lib/weft/query.rb', line 91

def to_s()
  path = @app.get_category(@identifier).path
  "( CODED BY(#{path}) )"
end