Class: Bukovina::Parsers::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/bukovina/parsers/link.rb

Constant Summary collapse

Parsers =
Bukovina::Parsers
RE =
/\A([#{Parsers::UPCHAR}#{Parsers::CHAR}#{Parsers::ACCENT}0-9\s‑;:'"«»\,()\.\-\?\/]+)\z/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



4
5
6
# File 'lib/bukovina/parsers/link.rb', line 4

def errors
  @errors
end

Instance Method Details

#parse(line) ⇒ Object

вход: значение поля “имя” включая словарь разных языков выход: обработанный словарь данных



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/bukovina/parsers/link.rb', line 12

def parse line
# TODO skip return if errors found
#
res =
case line
when Hash
   links = line.map do |(lang, url)|
      if url.is_a?( Array )
         url.map do |u|
            parse_line( u, lang ) ;end
         .compact
      else
         parse_line( url, lang ) ;end;end
   .compact.flatten
   { link: links }
when Array
   links = line.map do |url|
      if url.is_a?( Array )
         url.map do |u|
            parse_line( u ) ;end
         .compact
      else
         parse_line( url ) ;end;end
   .compact.flatten
   { link: links }
when String
   { link: [ parse_line( line ) ] }
when NilClass
else
   @errors << Parsers::BukovinaInvalidClass.new( "Invalid class " +
      "#{line.class} for Name line '#{line}'" ) ; end

@errors.empty? && res || nil ; end