Class: RD::RBLFile
- Inherits:
-
Object
- Object
- RD::RBLFile
- Includes:
- SearchFile
- Defined in:
- lib/rd2odt/rdtool/rd/rbl-file.rb
Constant Summary collapse
- SUFFIX =
"rbl"
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#labels ⇒ Object
readonly
Returns the value of attribute labels.
Class Method Summary collapse
- .basename(path) ⇒ Object
- .create_rbl_file(filename, resolver) ⇒ Object
- .labels_to_string(resolver) ⇒ Object
- .rbl_file_path(filename) ⇒ Object
Instance Method Summary collapse
-
#initialize(filename) ⇒ RBLFile
constructor
A new instance of RBLFile.
- #load_rbl_file(search_paths) ⇒ Object
- #parse_line(src) ⇒ Object
- #refer(label) ⇒ Object
- #string_to_labels(src) ⇒ Object
Methods included from SearchFile
Constructor Details
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
9 10 11 |
# File 'lib/rd2odt/rdtool/rd/rbl-file.rb', line 9 def filename @filename end |
#labels ⇒ Object (readonly)
Returns the value of attribute labels.
8 9 10 |
# File 'lib/rd2odt/rdtool/rd/rbl-file.rb', line 8 def labels @labels end |
Class Method Details
.basename(path) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/rd2odt/rdtool/rd/rbl-file.rb', line 26 def RBLFile.basename(path) if /\.(rd|rb)$/ === path $` else path end end |
.create_rbl_file(filename, resolver) ⇒ Object
16 17 18 19 20 |
# File 'lib/rd2odt/rdtool/rd/rbl-file.rb', line 16 def RBLFile.create_rbl_file(filename, resolver) file = File.open(RBLFile.rbl_file_path(filename), "w") file.print(RBLFile.labels_to_string(resolver)) file.close end |
.labels_to_string(resolver) ⇒ Object
34 35 36 37 38 |
# File 'lib/rd2odt/rdtool/rd/rbl-file.rb', line 34 def RBLFile.labels_to_string(resolver) (resolver.collect do |i| i.to_label + " => " + resolver.get_anchor(i) end).join("\n") end |
Instance Method Details
#load_rbl_file(search_paths) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/rd2odt/rdtool/rd/rbl-file.rb', line 40 def load_rbl_file(search_paths) f = search_file(@filename, search_paths, [SUFFIX]) raise "RBLFile not found." unless f src = File.readlines(f).join("") @labels = string_to_labels(src) end |
#parse_line(src) ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rd2odt/rdtool/rd/rbl-file.rb', line 55 def parse_line(src) col = src.rindex("=>") raise "RBL file parse error." unless col label = src[0 .. col - 1].strip anchor = src[col + 2 .. -1].strip [label, anchor] end |
#refer(label) ⇒ Object
63 64 65 66 67 |
# File 'lib/rd2odt/rdtool/rd/rbl-file.rb', line 63 def refer(label) label = @labels.find{|i| i[0] == label} return nil unless label label[1] end |
#string_to_labels(src) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/rd2odt/rdtool/rd/rbl-file.rb', line 47 def string_to_labels(src) labels = [] src.each_line do |i| labels << parse_line(i) end labels end |