Module: Exceler
- Defined in:
- lib/exceler.rb,
lib/exceler/version.rb
Defined Under Namespace
Classes: Item, ScanOption
Constant Summary collapse
- XLS =
"xls"
- XLSX =
"xlsx"
- EXT_PATTERNS =
[ XLS , XLSX ]
- DEFAULT_CSS =
"<style type='text/css'> .exceler-title h3 { color : blue; } .exceler-table { border-collapse: collapse; background-color: #ccf; width : 100%; border : 1px solid #888; } .exceler-table tr { border : 1px solid #888; } .exceler-table td { border : 1px solid #888; } </style>"
- VERSION =
"0.9.6"
Class Method Summary collapse
-
.export_item_html(items, title, subtitle) ⇒ Object
タスクの状況をHTMLにする。 transform task status to html string.
-
.list_assigned_person(items) ⇒ Object
渡されたアイテムのうち、割り当てられた人を一覧します。 list item assigned person.
-
.list_files(dir) ⇒ Object
- 指定されたディレクトリからファイル(.xls,.xlsx)を取得します find Excel files from the specified directory ==== Args dir
-
エクセルファイルを検索するディレクトリ ==== Return エクセルファイルの名前の配列.
-
.pickup_assigned(items, assign) ⇒ Object
渡されたアイテムのうち、特定の人に割り当てられたアイテムをピックアップします。 pickup specified person assigned items from the specified items.
-
.pickup_expired(items) ⇒ Object
期限切れのアイテムを探します pickup limit exceeded items from the specified items.
-
.pickup_incomplete(items) ⇒ Object
渡されたアイテムのうち未完了のアイテムをピックアップします。 pickup incompleted items from the specified items.
-
.scan_items(files, opt) ⇒ Object
Args files :: エクセルファイルの配列 opt :: 検索時のオプション、ScanOptionオブジェクト ==== Return アイテムの配列.
- .show_item(item) ⇒ Object
-
.write_csv_file(file, map) ⇒ Object
- マップオブジェクトをCSVをにして保存します。 ==== Args file
- output file map
-
map object ==== Return HTML Content.
-
.write_html_file(file, content, css) ⇒ Object
- 作成したHTMLファイルコンテンツにCSSを埋め込んで保存します。 ==== Args file
- output file content
-
Content of the file ==== Return HTML Content.
Class Method Details
.export_item_html(items, title, subtitle) ⇒ Object
タスクの状況をHTMLにする。 transform task status to html string.
Args
- items
-
アイテムの配列
Return
HTML Content
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/exceler.rb', line 293 def self.export_item_html( items , title , subtitle ) s="" if( title != nil ) s+="<p class='exceler-title'><h3>"+title if( subtitle != nil ) s+=+"-" + subtitle+ ":" + items.length.to_s end s+="</h3><br>" end s += "<table class='exceler-table'>" for item in items s+="<tr>" if( item.file != nil ) s+=( "<td>"+ item.file + "</td>" ) end if( item.content != nil ) s+=( "<td>"+ item.content.to_s + "</td>" ) end if( item.limit != nil ) s+=( "<td>"+ item.limit.to_s + "</td>" ) end s+="</td>" end s+= "</table>" s+= "</p>" return s end |
.list_assigned_person(items) ⇒ Object
渡されたアイテムのうち、割り当てられた人を一覧します。
list item assigned person.
Args
- items
-
アイテムの配列
Return
array of the assigned persons 担当になっている人の配列
213 214 215 216 217 218 219 220 221 |
# File 'lib/exceler.rb', line 213 def self.list_assigned_person( items ) pl = {} for item in items if( item.assign != nil ) pl[item.assign] = item end end return pl.keys end |
.list_files(dir) ⇒ Object
指定されたディレクトリからファイル(.xls,.xlsx)を取得します find Excel files from the specified directory
Args
- dir
-
エクセルファイルを検索するディレクトリ
Return
エクセルファイルの名前の配列
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/exceler.rb', line 84 def self.list_files( dir ) ret = []; for ext in EXT_PATTERNS filepattern = dir+File::SEPARATOR+"*."+ext; Dir[filepattern].each do |file| ret.push( file ) end end return ret end |
.pickup_assigned(items, assign) ⇒ Object
渡されたアイテムのうち、特定の人に割り当てられたアイテムをピックアップします。
pickup specified person assigned items from the specified items
Args
- items
-
アイテムの配列
- assign
-
担当
Return
array of the items which is asseigned to the sepecified person 担当に割あたっているアイテムの配列
233 234 235 236 237 238 239 240 241 |
# File 'lib/exceler.rb', line 233 def self.pickup_assigned( items , assign ) ret = [] for item in items if( item.assign == assign ) ret.push( item ) end end return ret end |
.pickup_expired(items) ⇒ Object
期限切れのアイテムを探します pickup limit exceeded items from the specified items
Args
- items
-
アイテムの配列
Return
array of the expired items 期限切れになっているアイテムの配列
270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/exceler.rb', line 270 def self.pickup_expired( items ) ret = [] current = Date.today incomplete = pickup_incomplete( items ) for item in incomplete if( item.limit != nil ) # puts item.limit.strftime("%Y/%m/%d")+"-"+current.strftime("%Y/%m%d") if( item.limit < current ) ret.push(item) end end end return ret end |
.pickup_incomplete(items) ⇒ Object
渡されたアイテムのうち未完了のアイテムをピックアップします。 pickup incompleted items from the specified items
Args
- items
-
アイテムの配列
Return
array of the incomplete items 未完了アイテムの配列
252 253 254 255 256 257 258 259 260 |
# File 'lib/exceler.rb', line 252 def self.pickup_incomplete( items ) ret = [] for item in items if( item.state == Item::INCOMPLETE ) ret.push( item ) end end return ret end |
.scan_items(files, opt) ⇒ Object
Args
- files
-
エクセルファイルの配列
- opt
-
検索時のオプション、ScanOptionオブジェクト
Return
アイテムの配列
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/exceler.rb', line 127 def self.scan_items( files , opt ) ret = [] if( opt == nil ) return nil end for file in files re = Regexp.new( XLS+"$" ) if( file =~ re ) # XLS file # puts "XLS file scan " + file s = Roo::Excel.new(file) else #XLSX file # puts "XLSX file scan"+file s = Roo::Excelx.new(file) end for sheet in s.sheets # if sheet option is nil then scan all sheets # else scan only one sheet that has the specified sheet name. if( opt.sheet != nil ) if( opt.sheet != sheet ) next end end s.default_sheet = sheet if( s.first_row == nil ) next else header = s.first_row end if( opt.header >= header ) header = opt.header end (header..s.last_row).each do |num| c = s.cell( opt.id_row , num ) if( c != nil ) i = Item.new i.file = file i.id = s.cell( opt.id_row, num ) if( opt.content_row != nil ) i.content = s.cell( opt.content_row ,num ) end if( opt.assign_row != nil ) i.assign = s.cell( opt.assign_row , num ) i.assign.strip! end if( opt.start_row != nil ) i.start = s.cell( opt.start_row , num ) end if( opt.limit_row != nil ) i.limit = s.cell( opt.limit_row , num ) end if( opt.state_row != nil ) if( opt.state_condition == nil ) if( s.cell( opt.state_row , num ) != nil ) i.state = Item::COMPLETE else i.state = Item::INCOMPLETE end else if( s.cell( opt.state_row ,num ) == opt.state_condition ) i.state = Item::COMPLETE else i.state = Item::INCOMPLETE end end end # show_item( i ) ret.push( i ) end end end end return ret end |
.show_item(item) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/exceler.rb', line 98 def self.show_item( item ) s = "" if( item.assign != nil ) s += ("assign:" + item.assign + "," ) end if( item.start != nil ) s += ( "start:" + item.start.strftime("%Y/%m/%d") + "," ) end if( item.limit != nil ) s += ( "limit:" + item.limit.strftime("%Y/%m/%d") + "," ) end if( item.state != nil ) if( item.state == Item::COMPLETE ) s += ( "state: complete ") else s += "state: incomplete" end end end |
.write_csv_file(file, map) ⇒ Object
マップオブジェクトをCSVをにして保存します。
Args
- file
-
output file
- map
-
map object
Return
HTML Content
364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/exceler.rb', line 364 def self.write_csv_file( file , map ) keys = map.keys ks = "" vs = "" for key in keys ks += (key + ",") vs += (map[key].to_s + "," ) end f = open( file , "w" ) f.puts( ks ) f.puts( vs ) f.flush() f.close() end |
.write_html_file(file, content, css) ⇒ Object
作成したHTMLファイルコンテンツにCSSを埋め込んで保存します。
Args
- file
-
output file
- content
-
Content of the file
Return
HTML Content
346 347 348 349 350 351 352 353 354 355 |
# File 'lib/exceler.rb', line 346 def self.write_html_file( file , content , css ) f = open( file , "w" ) if( css == nil ) css = DEFAULT_CSS end f.puts( DEFAULT_CSS ) f.puts( content ) f.flush() f.close() end |