Class: RakeMKV::Parser

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

Overview

Parser

Constant Summary collapse

CINFO_REGEX =
/CINFO:(\d+),\d+,"(.+)"/
DRIVES_REGEX =
/DRV:\d+,\d+,\d+,(\d+),"(.*)","(.*)","(.*)"/
MSG_REGEX =
/MSG:[^"]*"([^"]*)"/
SINFO_REGEX =
/SINFO:(\d+),(\d+),(\d+),\d+,"(.*)"/
TINFO_REGEX =
/TINFO:(\d+),(\d+),\d+,"(.*)"/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_info) ⇒ Parser

Initialize using info received from disc



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

def initialize(raw_info)
  @raw = raw_info
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



9
10
11
# File 'lib/rakemkv/parser.rb', line 9

def raw
  @raw
end

Instance Method Details

#cinfoObject

Grab information from cinfo



17
18
19
20
21
22
23
24
# File 'lib/rakemkv/parser.rb', line 17

def cinfo
  cinfo = {}
  parse(CINFO_REGEX) do |code, info|
    code = RakeMKV::Code[code]
    cinfo[code] = info
  end
  cinfo
end

#drivesObject

Grab information from discs



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rakemkv/parser.rb', line 61

def drives
  drives = []
  parse(DRIVES_REGEX) do |accessible, drive_name, disc_name, location|
    drives << {
      accessible: accessible(accessible),
      drive_name: drive_name,
      disc_name: disc_name,
      location: location
    }
  end
  drives
end

#messagesObject

Grab information from messages



52
53
54
55
56
57
58
# File 'lib/rakemkv/parser.rb', line 52

def messages
  messages = []
  parse(MSG_REGEX) do |info|
    messages << info.first
  end
  messages
end

#sinfoObject

Grab information from sinfo



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rakemkv/parser.rb', line 38

def sinfo
  sinfo = []
  parse(SINFO_REGEX) do |title_id, section_id, code, info|
    code = RakeMKV::Code[code]
    title = title_id.to_i
    section = section_id.to_i
    sinfo[title] ||= Array.new
    sinfo[title][section] ||= Hash.new
    sinfo[title][section][code] = info
  end
  sinfo
end

#tinfoObject

Grab information from tinfo



27
28
29
30
31
32
33
34
35
# File 'lib/rakemkv/parser.rb', line 27

def tinfo
  tinfo = []
  parse(TINFO_REGEX) do |title_id, code, info|
    code = RakeMKV::Code[code]
    tinfo[title_id.to_i] ||= Hash.new
    tinfo[title_id.to_i][code] = info
  end
  tinfo
end