tbpgr_utils 0.0.27 → 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,6 +30,7 @@ Or install it yourself as:
30
30
  |[TbpgrUtils Array#together_delete_at](#arraytogether_delete_at) |together version of Array#delete_at. together_delete_at has alias :tdelete_at |
31
31
  |[TbpgrUtils Array#together_delete_if](#arraytogether_delete_if) |together version of Array#delete_if. together_delete_if has alias :tdelete_if |
32
32
  |[TbpgrUtils Array#together_empty?](#arraytogether_empty) |together version of Array#empty?. together_empty? has alias :tempty? |
33
+ |[TbpgrUtils Array#together_fill](#arraytogether_fill) |together version of Array#fill. together_fill has alias :tfill |
33
34
  |[TbpgrUtils Array#together_map](#arraytogether_mapor-tmap-together_collect-tcollect) |together version of Enumerable#map. together_map has aliases [:tmap, :together_collect, :tcollect] |
34
35
  |[TbpgrUtils Array#together_map!](#arraytogether_map-1or-tmap-1-together_collect-1-tcollect-1) |together version of Enumerable#map!. together_map! has aliases [:tmap!, :together_collect!, :tcollect!] |
35
36
  |[TbpgrUtils Array#together_reduce](#arraytogether_reduceor-treduce-together_inject-tinject) |together version of Enumerable#reduce. together_reduce has aliases [:treduce, :together_inject, :tinject] |
@@ -39,6 +40,7 @@ Or install it yourself as:
39
40
  |[AttributesInitializable::ClassMethods.attr_accessor_init](#attributesinitializableclassmethodsattr_accessor_init) |generate attr_accessor + initializer |
40
41
  |[AttributesInitializable::ClassMethods.attr_reader_init](#attributesinitializableclassmethodsattr_reader_init) |generate attr_reader + initializer |
41
42
  |[AttributesInitializable::ClassMethods.attr_writer init](#attributesinitializableclassmethodsattr_writer_init) |generate attr_writer + initializer |
43
+ |[TbpgrUtils File.insert_bom](#fileinsert_bom) |insert BOM to UTF-8 File |
42
44
  |[Ghostable module](#ghostable) |help to create ghost method(dynamic method define by ussing method_missing + pattern-method-name) |
43
45
  |[TbpgrUtils Kernel#bulk_define_methods](#kernelbulk_define_methods) |define methods to classes. methods have simple return value. |
44
46
  |[TestToolbox Kernel#capture_stdout](#kernelcapture_stdout) |capture STDOUT |
@@ -256,6 +258,36 @@ print ret # => false
256
258
 
257
259
  [back to list](#list)
258
260
 
261
+ ### Array#together_fill
262
+ not use block case
263
+ ~~~ruby
264
+ require 'tbpgr_utils'
265
+
266
+ lists = [[*1..5], [*6..10]]
267
+ ret = lists.together_fill(99)
268
+ print ret # => [[99, 99, 99, 99, 99], [99, 99, 99, 99, 99]]
269
+ ~~~
270
+
271
+ use block, no args case
272
+ ~~~ruby
273
+ require 'tbpgr_utils'
274
+
275
+ lists = [[*1..5], [*6..10]]
276
+ ret = lists.together_fill { |i|(i + 1) + 1 }
277
+ print ret # => [[2, 3, 4, 5, 6], [2, 3, 4, 5, 6]]
278
+ ~~~
279
+
280
+ use block, has args case
281
+ ~~~ruby
282
+ require 'tbpgr_utils'
283
+
284
+ lists = [[*1..5], [*6..10]]
285
+ ret = lists.together_fill(2) { |i|(i + 1) + 1 }
286
+ print ret # => [[1, 2, 4, 5, 6], [6, 7, 4, 5, 6]]
287
+ ~~~
288
+
289
+ [back to list](#list)
290
+
259
291
  ### Array#together_map(or tmap, together_collect, tcollect)
260
292
  ~~~ruby
261
293
  require 'tbpgr_utils'
@@ -568,6 +600,25 @@ atr_sample2.instance_variable_get "@atr2" # => atr2
568
600
 
569
601
  [back to list](#list)
570
602
 
603
+ ### File.insert_bom
604
+ * this method's main purpose is 'UTF-8 Excel CSV File'.
605
+
606
+ output bommed text from input.csv to output.csv
607
+ ~~~ruby
608
+ require 'tbpgr_utils'
609
+
610
+ File.insert_bom("input.csv", "output.csv") # => output bommed text to output.csv
611
+ ~~~
612
+
613
+ output bommed text from input.csv to input.csv
614
+ ~~~ruby
615
+ require 'tbpgr_utils'
616
+
617
+ File.insert_bom("input.csv") # => output bommed text to output.csv
618
+ ~~~
619
+
620
+ [back to list](#list)
621
+
571
622
  ### Ghostable
572
623
  * include Ghostable
573
624
  * create ghost method by using Ghostable::ghost_method
@@ -980,6 +1031,7 @@ if you are Sublime Text2 user, you can use snippet for TbpgrUtils.
980
1031
  https://github.com/tbpgr/tbpgr_utils_snippets
981
1032
 
982
1033
  ## History
1034
+ * version 0.0.28 : add Array#together_fill(alias tfill). add File.insert_bom.
983
1035
  * version 0.0.27 : add Array#together_empty?(alias tempty?)
984
1036
  * version 0.0.26 : add Array#together_delete_if(alias tdelete_if)
985
1037
  * version 0.0.25 : add Array#together_delete_at(alias tdelete_at)
@@ -358,6 +358,38 @@ class Array
358
358
  is_empty
359
359
  end
360
360
 
361
+ # Arrays bulk fill.
362
+ #
363
+ # together_fill has alias :tfill
364
+ #
365
+ # not use block case
366
+ # lists = [[*1..5], [*6..10]]
367
+ # ret = lists.together_fill(99)
368
+ # print ret # => [[99, 99, 99, 99, 99], [99, 99, 99, 99, 99]]
369
+ #
370
+ # use block, no args case
371
+ # lists = [[*1..5], [*6..10]]
372
+ # ret = lists.together_fill { |i|(i + 1) + 1 }
373
+ # print ret # => [[2, 3, 4, 5, 6], [2, 3, 4, 5, 6]]
374
+ #
375
+ # use block, has args case
376
+ # lists = [[*1..5], [*6..10]]
377
+ # ret = lists.together_fill(2) { |i|(i + 1) + 1 }
378
+ # print ret # => [[1, 2, 4, 5, 6], [6, 7, 4, 5, 6]]
379
+ def together_fill(fill_value = nil, &block)
380
+ if_not_contain_array_rails_type_error
381
+ if block
382
+ fill_value = 0 if fill_value.nil?
383
+ first.each_with_index do |i_v, i|
384
+ next if i < fill_value
385
+ each { |list|list[i] = yield(i) }
386
+ end
387
+ else
388
+ each { |list|list.fill fill_value }
389
+ end
390
+ self
391
+ end
392
+
361
393
  private
362
394
 
363
395
  def if_not_contain_array_rails_type_error
@@ -414,6 +446,7 @@ class Array
414
446
  alias_method :tdelete_at, :together_delete_at
415
447
  alias_method :tdelete_if, :together_delete_if
416
448
  alias_method :tempty?, :together_empty?
449
+ alias_method :tfill, :together_fill
417
450
  alias_methods [:together_collect, :tmap, :tcollect], :together_map
418
451
  alias_methods [:together_collect!, :tmap!, :tcollect!], :together_map!
419
452
  alias_methods [:together_find_all, :tselect, :tfindall], :together_select
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ # File
4
+ class File
5
+ # insert BOM to UTF-8 File
6
+ #
7
+ # this method's main purpose is 'UTF-8 Excel CSV File'.
8
+ #
9
+ # File.insert_bom("input.csv", "output.csv") # => output bommed text to output.csv
10
+ # File.insert_bom("input.csv") # => output bommed text to input.csv
11
+ def self.insert_bom(input_filename, output_filename = nil)
12
+ src = File.read(input_filename)
13
+ output_filename ||= input_filename
14
+ File.open(output_filename, 'w:UTF-8') do |f|
15
+ src = ' ' + src
16
+ src.setbyte(0, 0xEF)
17
+ src.setbyte(1, 0xBB)
18
+ src.setbyte(2, 0xBF)
19
+ f.print src
20
+ end
21
+ end
22
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Tbpgr Utilities
4
4
  module TbpgrUtils
5
- VERSION = '0.0.27'
5
+ VERSION = '0.0.28'
6
6
  end
data/lib/tbpgr_utils.rb CHANGED
@@ -4,6 +4,7 @@ require 'tbpgr_utils/version'
4
4
  # Tbpgr Utilities
5
5
  module TbpgrUtils
6
6
  require 'open_classes/array'
7
+ require 'open_classes/file'
7
8
  require 'open_classes/kernel'
8
9
  require 'open_classes/module'
9
10
  require 'open_classes/object'