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.5"

Class Method Summary collapse

Class Method Details

.export_item_html(items, title, subtitle) ⇒ Object

タスクの状況をHTMLにする。transform task status to html string.

Args

items

アイテムの配列

Return

HTML Content



297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
# File 'lib/exceler.rb', line 297

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>" 
  # puts "------"
  # puts s 
  return s
end

.list_assigned_person(items) ⇒ Object

渡されたアイテムのうち、割り当てられた人を一覧します。

list item assigned person.

Args

items

アイテムの配列

Return

担当に割あたっている人の配列



217
218
219
220
221
222
223
224
225
# File 'lib/exceler.rb', line 217

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
94
# 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|  
#       puts "founds " + 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

担当に割あたっているアイテムの配列



237
238
239
240
241
242
243
244
245
# File 'lib/exceler.rb', line 237

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

期限切れになっているアイテムの配列



273
274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/exceler.rb', line 273

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

未完了アイテムの配列



255
256
257
258
259
260
261
262
263
# File 'lib/exceler.rb', line 255

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

アイテムの配列



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
202
203
204
205
# File 'lib/exceler.rb', line 129

def self.scan_items( files , opt )
  ret = []
  if( opt == nil )
    return nil
  end
  for file in files
    puts file
    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 )
            puts opt.state_row
            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



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/exceler.rb', line 99

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
  puts s
end

.write_csv_file(file, map) ⇒ Object

マップオブジェクトをCSVをにして保存します。

Args

file

output file

content

Content of the file

Return

HTML Content



372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/exceler.rb', line 372

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



353
354
355
356
357
358
359
360
361
362
# File 'lib/exceler.rb', line 353

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