Module: ODDB::IndexedInterval

Includes:
Interval
Included in:
State::Analysis::Alphabetical, State::Drugs::Fachinfos, State::Drugs::LimitationTexts, State::Drugs::Narcotics, State::Drugs::Patinfos, State::Drugs::Sequences, State::Drugs::Vaccines, State::Migel::Alphabetical
Defined in:
src/util/interval.rb

Constant Summary

RANGE_PATTERNS =
('a'..'z').to_a.push('0-9')

Constants included from Interval

FILTER_THRESHOLD, PERSISTENT_RANGE, RANGE_PATTERNS

Instance Method Summary (collapse)

Methods included from Interval

#filter_interval, #get_intervals, #range_patterns, #symbol, #user_range

Instance Method Details

- (Object) comparison_value(item)



80
81
82
# File 'src/util/interval.rb', line 80

def comparison_value(item)
  item.send(*symbol).to_s.downcase
end

- (Object) default_interval



83
84
# File 'src/util/interval.rb', line 83

def default_interval
end

- (Object) filter(model)



101
102
103
# File 'src/util/interval.rb', line 101

def filter(model)
  load_model
end

- (Object) index_lookup(query)



107
108
109
# File 'src/util/interval.rb', line 107

def index_lookup(query)
  ODBA.cache.retrieve_from_index(index_name, query)
end

- (Object) index_name



110
111
# File 'src/util/interval.rb', line 110

def index_name
end

- (Object) init



75
76
77
78
79
# File 'src/util/interval.rb', line 75

def init
  super
  @model = []
  @filter = method(:filter)
end

- (Object) interval



104
105
106
# File 'src/util/interval.rb', line 104

def interval
  @range
end

- (Object) intervals



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'src/util/interval.rb', line 112

def intervals
  @intervals or begin
    values = ODBA.cache.index_keys(index_name, 1).delete_if { |key|
      key.empty? }
    @intervals, @numbers = values.partition { |char|
      /[a-z]/ui.match(char)
    }
    unless(@numbers.empty?)
      @intervals.push('0-9')
    end
    @intervals
  end
end

- (Object) load_model



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'src/util/interval.rb', line 85

def load_model
  if((tmp_rng = user_range) && tmp_rng != @range)
    @model.clear
    parts = @range = tmp_rng
    if(@range == '0-9')
      intervals
      parts = @numbers
    end
    parts.each { |part|
      @model.concat(index_lookup(part).sort_by { |item| 
        comparison_value(item)
      })
    }
  end
  @model
end