Top Level Namespace
Defined Under Namespace
Modules: Rsssf
Constant Summary collapse
- RsssfPage =
add (shortcut) alias(es)
Rsssf::Page
- RsssfPageConverter =
Rsssf::PageConverter
- RsssfPageStat =
Rsssf::PageStat
- RsssfPageReport =
Rsssf::PageReport
- RsssfSchedule =
Rsssf::Schedule
- RsssfScheduleStat =
Rsssf::ScheduleStat
- RsssfScheduleReport =
Rsssf::ScheduleReport
- RsssfUtils =
Rsssf::Utils
- VARDEF_RE =
use/rename to VARDEF_LINE or such - why? why not?
%r{\A [ ]* \$(?<key> [a-z][a-z0-9_]*) [ ]* = [ ]* (?<value> .+?) ## eat-up (non-greedy) the rest until end-of-line [ ]* \z }ix- VAR_RE =
%r{ \$(?<key> [a-z][a-z0-9_]*) \b }ix- BOLD_OR_UNDERLINE_LINE_RE =
scan for now only (do NOT replace)
%r{^ [ ]* < (?<tag> [BU]) > [ ]* (?<text> .+? ## note - use non-greedy match ) [ ]* </ \k<tag> > [ ]* $}ix
Instance Method Summary collapse
-
#_cocos_ ⇒ Object
move/add to upstream!!!.
-
#banner ⇒ Object
say hello.
-
#find_file(name, path:) ⇒ Object
note - find_file will NOT find directories!!! File.file? will only check if a file (not directory) exits!!.
- #find_file!(name, path:) ⇒ Object
- #make_heading(html) ⇒ Object
- #parse_patterns(txt) ⇒ Object
-
#parse_schedules(txt) ⇒ Object
todo/check - find a better name rename to parse_sections/leagues/??? - why? why not?.
- #read_patterns(path) ⇒ Object
- #read_schedules(path) ⇒ Object
Instance Method Details
#_cocos_ ⇒ Object
move/add to upstream!!!
10 |
# File 'lib/rsssf.rb', line 10 require_relative '_cocos_' |
#find_file(name, path:) ⇒ Object
note - find_file will NOT find directories!!!
File.file? will only check if a file (not directory) exits!!
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/_cocos_.rb', line 47 def find_file( name, path: ) return name if File.file?( name ) path.each do |dir| filepath = File.join( dir, name ) return filepath if File.file?( filepath ) end nil ## return nil if not found end |
#find_file!(name, path:) ⇒ Object
37 38 39 40 41 |
# File 'lib/_cocos_.rb', line 37 def find_file!( name, path: ) filepath = find_file( name, path: path ) raise Errorno::ENOENT, "file <#{name}> not found; looking in path #{path.inspect}" if filepath.nil? filepath end |
#make_heading(html) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rsssf/convert/html_to_txt/make_heading.rb', line 34 def make_heading( html ) edits = [] html = html.gsub( BOLD_OR_UNDERLINE_LINE_RE ) do |match| m = Regexp.last_match tag = m[:tag].downcase text = m[:text] if text.downcase.start_with?( '<a name' ) msg = "make heading (h#{tag}) out of #{tag}-enclosed a name in line >#{text}<" puts " #{msg}" ## note - edit line MUST start with -- ## might be multi-line edits << "-- #{msg}" "<h#{tag}>#{text}</h#{tag}>" else ## note - skip (false positive) copyright line (in about this document) ## (C) Copyright RSSSF ## Copyright if %r{copyright}i.match?( text ) else msg = "found #{tag}-enclosed line >#{text}< - heading?" puts " #{msg}" edits << "-- #{msg}" end match ## keep as is (do NOT change) end end [html, edits] end |
#parse_patterns(txt) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 152 153 154 155 156 157 158 |
# File 'lib/_cocos_.rb', line 87 def parse_patterns( txt ) ## norm newline (windows cr/lf \r\n) to (lf - \n) txt = txt.gsub( /\r\n/, "\n" ) ### check for line continuations with backslash (\) ## note - allow spaces before newline txt = txt.gsub( /\\[ ]*$\n/, '' ) vars = {} names = [] # array of lines (with words) txt.each_line do |line| line = line.strip next if line.empty? next if line.start_with?( '#' ) ## skip comments too break if line == '__END__' ## strip inline (until end-of-line) comments too ## e.g. Janvier Janv Jan ## check janv in use?? ## => Janvier Janv Jan line = line.sub( /#.*/, '' ).strip ## pp line ### ## check for variable defs if m = VARDEF_RE.match( line ) vars[ m[:key].downcase ] = m[:value ] next end line = line.gsub( VAR_RE ) do |_| m = Regexp.last_match key = m[:key].downcase value = vars[key] raise ArgumentError, "subvars - no vardef found for key >#{key}<" if value.nil? value end ### use squish - remove more than one inline space line = line.gsub( /[ ]{2,}/, ' ' ) ## open paren (use for grouping to non-capture grouping) e.g. ## () => (?: ) ## note - do NOT replace escaped /( !!! ## e.g. playoffs (liguilla) line = line.gsub( / ## negative lookbehind (?<! \\) \( /x, '(?: ') ## expand space shortcuts ## replace Middle Dot (·) Unicode: U+00B7 or ## White Square (□) Unicode: U+25A1 or ## White Small Square (▫) Unicode: U+25AB ## Open Box (␣) Unicode: U+2423 or ## ## add more - why? why not? line = line.gsub( /[·□▫␣]/, ' [ ] ' ) names << line end names end |
#parse_schedules(txt) ⇒ Object
todo/check - find a better name
rename to parse_sections/leagues/??? - why? why not?
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/rsssf/parse_schedules.rb', line 6 def parse_schedules( txt ) rows = parse_csv( txt ) ## transform seasons column to seasons objects rows.each do |row| if row['seasons'] && !row['seasons'].empty? row['seasons'] = Season.parse_line( row['seasons'] ) end end rows end |
#read_patterns(path) ⇒ Object
83 84 85 |
# File 'lib/_cocos_.rb', line 83 def read_patterns( path ) parse_patterns( read_text( path )) end |
#read_schedules(path) ⇒ Object
16 |
# File 'lib/rsssf/parse_schedules.rb', line 16 def read_schedules( path ) parse_schedules( read_text(path)); end |