Module: Exceler

Defined in:
lib/exceler.rb,
lib/exceler/version.rb

Defined Under Namespace

Classes: Foo, Item, ScanOption

Constant Summary collapse

XLS =
"xls"
XLSX =
"xlsx"
EXT_PATTERNS =
[ XLS , XLSX ]
VERSION =
"0.9.2"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.hello2Object



8
9
10
# File 'lib/exceler.rb', line 8

def self.hello2
  puts "helo2"
end

.list_files(dir) ⇒ Object

指定されたディレクトリからファイル(.xls,.xlsx)を取得しますfind Excel files from the specified directory

Args

dir

エクセルファイルを検索するディレクトリ

Return

エクセルファイルの名前の配列



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/exceler.rb', line 87

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

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



209
210
211
212
213
214
215
216
217
# File 'lib/exceler.rb', line 209

def self.pickup_assigned( items , assign )
  ret = []
  for item in items
    if( item.assign == assign )
      ret.push( item )
    end
  end
  return ret
end

.pickup_expiration(items) ⇒ Object

期限切れのアイテムを探しますpickup limit exceeded items from the specified items

Args

items

アイテムの配列

Return

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



245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/exceler.rb', line 245

def self.pickup_expiration( 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

未完了アイテムの配列



227
228
229
230
231
232
233
234
235
# File 'lib/exceler.rb', line 227

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

アイテムの配列



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
# File 'lib/exceler.rb', line 132

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
      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
          if( opt.assign_row != nil )
            i.assign = s.cell( opt.assign_row , num )
          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 )
        else
          puts "skip!!"
        end
      end
    end
  end
  return ret
end

.show_item(item) ⇒ Object



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

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

Instance Method Details

#helloObject



4
5
6
# File 'lib/exceler.rb', line 4

def hello
  puts "hello"
end