Class: Es::Field

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

Overview

Fields

Constant Summary collapse

ATTRIBUTE_TYPE =
"attribute"
RECORDID_TYPE =
"recordid"
DATE_TYPE =
"date"
TIME_TYPE =
"time"
FACT_TYPE =
"fact"
TIMESTAMP_TYPE =
"timestamp"
AUTOINCREMENT_TYPE =
"autoincrement"
SNAPSHOT_TYPE =
"snapshot"
HID_TYPE =
"hid"
HISTORIC_TYPE =
"historicid"
DURATION_TYPE =
"duration"
VELOCITY_TYPE =
"velocity"
IS_DELETED_TYPE =
"isDeleted"
TIMEATTRIBUTE_TYPE =
"timeAttribute"
FIELD_TYPES =
[ATTRIBUTE_TYPE, RECORDID_TYPE, DATE_TYPE, TIME_TYPE, FACT_TYPE, TIMESTAMP_TYPE, AUTOINCREMENT_TYPE, SNAPSHOT_TYPE, HID_TYPE, HISTORIC_TYPE, DURATION_TYPE, VELOCITY_TYPE, IS_DELETED_TYPE,TIMEATTRIBUTE_TYPE]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Field

Returns a new instance of Field.



621
622
623
624
625
626
627
# File 'lib/es.rb', line 621

def initialize(name, type)
  fail Es::IncorrectSpecificationError.new("The field name \"#{name.bright}\" does not have type specified. Type should be one of [#{FIELD_TYPES.join(', ')}]") if type.nil?
  fail Es::IncorrectSpecificationError.new("The type of field name \"#{name.bright}\" should be a string.") unless type.is_a?(String)
  fail Es::IncorrectSpecificationError.new("The field name \"#{name.bright}\" does have wrong type specified. Specified \"#{type.bright}\" should be one of [#{FIELD_TYPES.join(', ')}]") unless FIELD_TYPES.include?(type) || type == "none"
  @name = name
  @type = type
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



579
580
581
# File 'lib/es.rb', line 579

def name
  @name
end

#typeObject

Returns the value of attribute type.



579
580
581
# File 'lib/es.rb', line 579

def type
  @type
end

Class Method Details

.parse(spec) ⇒ Object



573
574
575
576
577
# File 'lib/es.rb', line 573

def self.parse(spec)
  fail InsufficientSpecificationError.new("Field specification is empty") if spec.nil?
  fail InsufficientSpecificationError.new("Field specification is should be an object") unless spec.is_a?(Hash)
  Field.new(spec[:name], spec[:type])
end

Instance Method Details

#==(other) ⇒ Object



669
670
671
# File 'lib/es.rb', line 669

def ==(other)
  other.name == name
end

#is_attribute?Boolean

Returns:

  • (Boolean)


589
590
591
# File 'lib/es.rb', line 589

def is_attribute?
  type == ATTRIBUTE_TYPE
end

#is_autoincrement?Boolean

Returns:

  • (Boolean)


609
610
611
# File 'lib/es.rb', line 609

def is_autoincrement?
  false
end

#is_date?Boolean

Returns:

  • (Boolean)


597
598
599
# File 'lib/es.rb', line 597

def is_date?
  type == DATE_TYPE
end

#is_duration?Boolean

Returns:

  • (Boolean)


605
606
607
# File 'lib/es.rb', line 605

def is_duration?
  false
end

#is_fact?Boolean

Returns:

  • (Boolean)


593
594
595
# File 'lib/es.rb', line 593

def is_fact?
  type == FACT_TYPE
end

#is_hid?Boolean

Returns:

  • (Boolean)


613
614
615
# File 'lib/es.rb', line 613

def is_hid?
  false
end

#is_recordid?Boolean

Returns:

  • (Boolean)


581
582
583
# File 'lib/es.rb', line 581

def is_recordid?
  type == RECORDID_TYPE
end

#is_snapshot?Boolean

Returns:

  • (Boolean)


601
602
603
# File 'lib/es.rb', line 601

def is_snapshot?
  false
end

#is_timestamp?Boolean

Returns:

  • (Boolean)


585
586
587
# File 'lib/es.rb', line 585

def is_timestamp?
  type == TIMESTAMP_TYPE
end

#is_velocity?Boolean

Returns:

  • (Boolean)


617
618
619
# File 'lib/es.rb', line 617

def is_velocity?
  false
end

#to_config_generatorObject



657
658
659
660
661
662
# File 'lib/es.rb', line 657

def to_config_generator
 	d = ActiveSupport::OrderedHash.new
    d['name'] = name
    d['type'] = Es::Helpers.type_to_generator_load_type(type)
    d
end

#to_config_generator_extractObject



665
666
667
# File 'lib/es.rb', line 665

def to_config_generator_extract
      name
end

#to_extract_fragment(pid, fields, options = {}) ⇒ Object



629
630
631
632
633
634
635
636
637
638
639
640
641
# File 'lib/es.rb', line 629

def to_extract_fragment(pid,fields, options = {})
  {
    :name => name,
    :preferred => name,
    :definition => {
      :ops => [{
        :type => Es::Helpers.type_to_type(type),
        :data => name
      }],
      :type => Es::Helpers.type_to_operation(type)
    }
  }
end

#to_load_configObject



650
651
652
653
654
655
# File 'lib/es.rb', line 650

def to_load_config
  {
    :name => name,
    :type => (type == 'none' ? '' : type)
  }
end

#to_load_fragment(pid) ⇒ Object



643
644
645
646
647
648
# File 'lib/es.rb', line 643

def to_load_fragment(pid)
  {
    :name => name,
    :type => Es::Helpers.type_to_load_type(type)
  }
end