Sha256: d876a372ee42ce45f0d51e7fb3b7ee2bdb63b780b0151af4a051167cc2af054f

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

module AmoCRM::Entities
  class Attribute < Base
    include AmoCRM::Entities::Common

    tag 'attribute'

    # 
    attribute :metadataUuid,    String
    attribute :valueString,     String
    attribute :valueText,       String
    attribute :doubleValue,     Float
    attribute :longValue,       Integer
    attribute :booleanValue,    Boolean
    attribute :timeValue,       String

    attribute :agentValueUuid, String
    attribute :goodValueUuid, String
    attribute :placeValueUuid, String
    attribute :consignmentValueUuid, String
    attribute :employeeValueUuid, String
    attribute :projectValueUuid, String
    attribute :contractValueUuid, String

    attribute :file, AmoCRM::Entities::AttachmentDocument

    attribute :entityValueUuid, String

    # Объект описывающий тип атритуба
    #
    # @return AmoCRM::Entities::AttributeMetadata
    #
    def metadata universe
      universe.embedded_entity_metadata.subresource_by_name(:GoodFolder).find metadataUuid
    end

    # Название свойства, полученное из AttributeMetadata
    #
    # @return String
    #
    def attributeName universe
      metadata(universe).name
    end

    # Значение свойства согласно его типу
    #
    # @return [String | AmoCRM::Entities::CustomEntity | Integer | Decimal ]
    def get_value universe
      md = metadata universe
      case md.attrType
      when 'ID_CUSTOM'
        universe.custom_entities.find( entityValueUuid ).name
      when 'LINK'
        valueText
      when 'TEXT'
        valueText
      when 'STRING'
        valueString
      when 'DOUBLE'
        doubleValue
      when 'LONG'
        longValue
      when 'TIME'
        timeValue
      when 'FILE'
        file
      else
        raise "Не известный тип мета-аттрибута #{md.uuid}: #{md.attrType}"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
amo_crm-0.2.2 lib/amo_crm/entities/attribute.rb