class RealPage::Model::Base::Attribute

Encapsulate a model attribute

Attributes

name[R]
prefix[R]
type[R]

Public Class Methods

new(prefix:, type:, name:) click to toggle source
# File lib/real_page/model/base/attribute.rb, line 8
def initialize(prefix:, type:, name:)
  @prefix = prefix
  @type = type
  @name = name.to_s
end

Public Instance Methods

accessor_name() click to toggle source

@return [String] the name of the method on the model used to access

this attribute
# File lib/real_page/model/base/attribute.rb, line 16
def accessor_name
  type == :boolean ? "#{name}?" : name
end
matches?(attr) click to toggle source

There is some magic happening here to support more convenient attribute names. Since Model::Base.new can take parameters from a parsed XML document or from a human, we need to be able to look up the attribute based on either. The general mapping looks like:

XML node      | attribute name

—————+——————–

SomeThing     | some_thing
something     | some_thing
foobarid      | bar_id (if in Model::Foo)
somethingbit  | some_thing (if defined as a :boolean)
somethingflag | some_thing (if defined as a :boolean)

@param attr [String|Symbol] the name of the attribute or the XML node

name from the RealPage response, e.g. :made_ready_date or
"MadeReadyDate"

@return [true|false] true iff the value passed in is for this

Attribute
# File lib/real_page/model/base/attribute.rb, line 38
def matches?(attr)
  possible_names.include?(attr.to_s.downcase)
end

Private Instance Methods

possible_names() click to toggle source
# File lib/real_page/model/base/attribute.rb, line 44
def possible_names
  squished_name = name.gsub(/_/, '')
  prefixed_name = "#{prefix}#{squished_name}"
  names = [name, squished_name, prefixed_name]
  if type == :boolean
    names.concat(["#{squished_name}flag", "#{squished_name}bit"])
  end
  names
end