Class: ParsingStructure

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

Instance Method Summary collapse

Constructor Details

#initialize(structure) ⇒ ParsingStructure

Returns a new instance of ParsingStructure.



5
6
7
8
9
# File 'lib/parsing_structure.rb', line 5

def initialize(structure)
  @structure = structure

  @array_of_full_data = []
end

Instance Method Details

#get_year_month_dayObject



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
# File 'lib/parsing_structure.rb', line 53

def get_year_month_day
  set_year_month_day_time

  if @structure
    @structure.each do |item|
      if item[:type] == :year
        @year = item[:value]
      end

      if item[:type] == :month
        @month = item[:value]
      end

      if item[:type] == :day
        @day = item[:value]
      end

      if @year && @month && @day
        @array_of_full_data << [@year,@month,@day].join("-")
      end
    end
  end

  @array_of_full_data
end

#get_year_month_day_timeObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/parsing_structure.rb', line 23

def get_year_month_day_time
  set_year_month_day_time

  if @structure
    @structure.each do |item|
      if item[:type] == :year
        @year = item[:value]
      end

      if item[:type] == :month
        @month = item[:value]
      end

      if item[:type] == :day
        @day = item[:value]
      end

      if item[:type] == :time
        @time = item[:value]
      end

      if @year && @month && @day && @time
        @array_of_full_data << [[@year,@month,@day].join("-"), @time].join(" ")
      end
    end
  end

  @array_of_full_data
end

#set_year_month_day_timeObject



79
80
81
82
83
84
# File 'lib/parsing_structure.rb', line 79

def set_year_month_day_time
  @year = nil
  @month = nil
  @day = nil
  @time = nil
end

#startObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/parsing_structure.rb', line 11

def start
  if @structure
    if (@structure.select {|father| father[:type] == :time }).any?
      get_year_month_day_time
    else
      get_year_month_day
    end
  end

  return @array_of_full_data
end