Class: Norikra::Target

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, fields = [], auto_field = true) ⇒ Target

Returns a new instance of Target.



9
10
11
12
13
14
# File 'lib/norikra/target.rb', line 9

def initialize(name, fields=[], auto_field=true)
  @name = name
  @fields = fields
  @auto_field = !!auto_field
  @last_modified = nil
end

Instance Attribute Details

#auto_fieldObject

Returns the value of attribute auto_field.



3
4
5
# File 'lib/norikra/target.rb', line 3

def auto_field
  @auto_field
end

#fieldsObject

Returns the value of attribute fields.



3
4
5
# File 'lib/norikra/target.rb', line 3

def fields
  @fields
end

#last_modifiedObject

Returns the value of attribute last_modified.



3
4
5
# File 'lib/norikra/target.rb', line 3

def last_modified
  @last_modified
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/norikra/target.rb', line 3

def name
  @name
end

Class Method Details

.valid?(target_name) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/norikra/target.rb', line 5

def self.valid?(target_name)
  target_name =~ /^[a-zA-Z]([_a-zA-Z0-9]*[a-zA-Z0-9])?$/
end

Instance Method Details

#<=>(other) ⇒ Object



16
17
18
# File 'lib/norikra/target.rb', line 16

def <=>(other)
  self.name <=> other.name
end

#==(other) ⇒ Object



24
25
26
# File 'lib/norikra/target.rb', line 24

def ==(other)
  self.class == other.class ? self.name == other.name : self.name == other.to_s
end

#auto_field?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/norikra/target.rb', line 28

def auto_field?
  @auto_field
end

#to_hashObject



20
21
22
# File 'lib/norikra/target.rb', line 20

def to_hash
  {name: @name, auto_field: @auto_field}
end

#update!Object



32
33
34
# File 'lib/norikra/target.rb', line 32

def update!
  @last_modified = Time.now
end