Class: Label

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

Overview

The Label class - Attempting retrieve relavant information from a label

Constant Summary collapse

DEFAULT_VALUE =

TODO: humanize_label_date

'Blank'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Label


19
20
21
22
23
24
25
26
27
28
# File 'lib/label.rb', line 19

def initialize(name)
  @name = name
  @series = DEFAULT_VALUE
  @version = DEFAULT_VALUE
  @platform = DEFAULT_VALUE
  @date_time = DEFAULT_VALUE
  @date = DEFAULT_VALUE
  @time = DEFAULT_VALUE
  @validation_status = DEFAULT_VALUE
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date


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

def date
  @date
end

#date_timeObject (readonly)

Returns the value of attribute date_time


15
16
17
# File 'lib/label.rb', line 15

def date_time
  @date_time
end

#nameObject (readonly)

Currently having these attributes as read only. also having date_time as a seperate variable to obtain segment 4 of a label


11
12
13
# File 'lib/label.rb', line 11

def name
  @name
end

#platformObject (readonly)

Returns the value of attribute platform


14
15
16
# File 'lib/label.rb', line 14

def platform
  @platform
end

#seriesObject (readonly)

Returns the value of attribute series


12
13
14
# File 'lib/label.rb', line 12

def series
  @series
end

#timeObject (readonly)

Returns the value of attribute time


17
18
19
# File 'lib/label.rb', line 17

def time
  @time
end

#validation_statusObject (readonly)

Returns the value of attribute validation_status


18
19
20
# File 'lib/label.rb', line 18

def validation_status
  @validation_status
end

#versionObject (readonly)

Returns the value of attribute version


13
14
15
# File 'lib/label.rb', line 13

def version
  @version
end

Instance Method Details

#retrieve_date_timeObject

remember you need to call retrieve segments from label TODO: need to find how to call retrieve segments from label within this


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/label.rb', line 81

def retrieve_date_time
  # before we retrieve date and time, we need obtain date_time segment
  
  self.retrieve_segments_from_label
  
  
  
  # defining the pattern through englished regular expression
  # even though it is only a .
  pattern_for_dot = VerEx.new do
    find '.'
  end

  @date = @date_time.match(pattern_for_dot).pre_match
  @time = @date_time.match(pattern_for_dot).post_match
end

#retrieve_segments_from_labelObject

TODO: rename method


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/label.rb', line 48

def retrieve_segments_from_label
  # defining the pattern through englished regular expression
  pattern_for_segments = VerEx.new do
    start_of_line
    begin_capture 'series'
    anything_but '_'
    end_capture
    # First Underscore
    find '_'
    begin_capture 'version'
    anything_but '_'
    end_capture
    # Second Underscore
    find '_'
    begin_capture 'platforms'
    anything_but '_'
    end_capture
    # Third Underscore
    find '_'
    begin_capture 'date_time'
    anything_but '_'
    end_capture
  end

  @name.match(pattern_for_segments) do |match_values|
    @series = match_values['series']
    @version =  match_values['version']
    @platform = match_values['platforms']
    @date_time = match_values['date_time']
  end

  # remember you need to call retrieve segments from label
  # TODO: need to find how to call retrieve segments from label within this
  def retrieve_date_time
    # before we retrieve date and time, we need obtain date_time segment
    
    self.retrieve_segments_from_label
    
    
    
    # defining the pattern through englished regular expression
    # even though it is only a .
    pattern_for_dot = VerEx.new do
      find '.'
    end

    @date = @date_time.match(pattern_for_dot).pre_match
    @time = @date_time.match(pattern_for_dot).post_match
  end
end

#validate_labelObject

Validating if there are 3 underscores


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/label.rb', line 31

def validate_label
  # defining a pattern
  pattern_for_underscores = VerEx.new do
    find '_'
  end

  # string.scan(pattern_to_scan)
  if @name.scan(pattern_for_underscores).count == 3

    then @validation_status = 'success'

  else @validation_status = 'validation failed - I did not get 3 underscores'

  end
end