Module: MyMedia::IndexReader
- Includes:
- RXFRead
- Defined in:
- lib/mymedia.rb
Instance Method Summary collapse
- #browse(startswith = nil) ⇒ Object
- #find(keyword) ⇒ Object
- #find_sourcefile(id) ⇒ Object
- #search(keyword) ⇒ Object
Instance Method Details
#browse(startswith = nil) ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/mymedia.rb', line 118 def browse(startswith=nil) json_filepath = "%s/%s/%s/dynarex.json" % [@home, @www, @public_type] if FileX.exists? json_filepath then dx = DxLite.new(json_filepath) if startswith then @stopwords = WordsDotDat.stopwords q = startswith r = dx.all.select do |x| found = x.title.scan(/\b\w+/).select do |raw_word| word = raw_word.downcase word[0..(q.length-1)] == q and not @stopwords.include? word end found.any? end else return dx.all end end end |
#find(keyword) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/mymedia.rb', line 153 def find(keyword) json_filepath = File.join(@home, @www, @public_type, 'dynarex.json') if FileX.exists? json_filepath then dx = DxLite.new(json_filepath) return dx.all.find do |x| regex = keyword.is_a?(String) ? /#{keyword}/i : keyword x.title =~ regex end end end |
#find_sourcefile(id) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/mymedia.rb', line 191 def find_sourcefile(id) json_filepath = File.join(@home, @www, @public_type, 'dynarex.json') if FileX.exists? json_filepath then dx = DxLite.new(json_filepath) rx = dx.find_by_id(id) Kvx.new(@home + rx.).file end end |
#search(keyword) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/mymedia.rb', line 172 def search(keyword) json_filepath = File.join(@home, @www, @public_type, 'dynarex.json') if FileX.exists? json_filepath then dx = DxLite.new(json_filepath) return dx.all.select do |x| regex = keyword.is_a?(String) ? /#{keyword}/i : keyword x.title =~ regex end end end |