mobj 2.5.0 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +8 -8
  2. data/lib/ext/array.rb +2 -0
  3. data/lib/ext/string.rb +45 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OTc4M2ZkNTIyNGQ0MzY3NGNhMWYxOTk3YmNlNTJkZjdiNGQxM2M2OA==
4
+ MWJmMjVjMjVmZDI0MmQ0ZjkyODBhZjY3ZmYwMWU3MWQyMjkxMDdlZQ==
5
5
  data.tar.gz: !binary |-
6
- ZWUzM2ZkYzRjNTMxZWRkYzUzODBiN2VjMjI1YjZjODM1ZmZkNGMwZg==
6
+ NDM2M2FjMmQ4MzY3NjI0OTRlZDc0YTVjNjNlMmUwZDliZGYzYjgyMQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NzE1ZTFiMmRkODVjZDA4ZTBiMGJiOGRhZTQ0NmY1NmIxZDA5YTkxNTRhZGZm
10
- ODFmNThiOTkyYTdkMDc4YjgzYTk0N2M1ZGU2NmZiMGMzYTkwYjI1MGZkMDli
11
- ZjgzNWEyYjM0ZjJjYmI1ODEyZTFmMzFiODI4Y2M2YWFhOWNjNzc=
9
+ ZGYzOGE5NDFkOGU0YTJhNDNiN2M1MTM2MTE1MjllM2FhZmY4NzdiNzNkODY2
10
+ N2RiOGQwMTFkMjQ3YzU0N2U4ZTU1MDM2YmJkODljYmYyNjZkODU3MGRmYzY4
11
+ NTc1ZjM0MTljNTIwNzkwMmRjYzMyMTRkNTViMzk3YjJjMmI4MjA=
12
12
  data.tar.gz: !binary |-
13
- NzM0MThiZjkwMjY0MWRhN2U0ZTljYjhhMDIxYzI1NGM5YzE5NGJjOTgzY2Yx
14
- YjA2Y2Y4M2VjMDExMTUxZmFiNTcxYjdjZmNjODViNTVlNDAzMzE5MjI0Mzk0
15
- YzgyYjI1OTU4MmE4ZmViMDMwOTliZDBiMjk4OGYzNDllZmQxOTM=
13
+ ZjZmNTk3ZGJlMmY3OWJiMjJmOTRhYWM2NGMxNjljODBhMzMxNDBmNzUwOWQ5
14
+ NDdmMWVjMzBkZmQyZWQ1YjkyNDc1N2MzY2VkMjY2NzU2OTJlNjBlN2JhY2Jk
15
+ OTIzOWYyYjJhZDc2YzkzZjliOGNiMGQzOThlMWM4YTQ3MGVjMWM=
@@ -35,6 +35,8 @@ module Mobj
35
35
  each { |item| break if (returned = block.call(item)) }
36
36
  returned
37
37
  end
38
+
39
+ alias_method :earliest, :return_first
38
40
  end
39
41
 
40
42
  end
@@ -2,8 +2,53 @@ require 'mobj'
2
2
 
3
3
  module Mobj
4
4
 
5
+ ANSI = {
6
+ colors: {
7
+ k: 0, #:black,
8
+ r: 1, #:red,
9
+ g: 2, #:green,
10
+ y: 3, #:yellow,
11
+ b: 4, #:blue,
12
+ m: 5, #:magenta,
13
+ c: 6, #:cyan,
14
+ w: 7 #:white,
15
+ },
16
+ options: {
17
+ #:'*' => 90, #:bright,
18
+ #:'^' => 90, #:bright,
19
+ :'!' => 1, #:bold,
20
+ B: 1, #:bold,
21
+ f: 2, #:faint,
22
+ i: 3, #:italics,
23
+ u: 4, #:underline,
24
+ _: 4, #:underline,
25
+ x: 5, #:blink,
26
+ F: 6, #:blink_fast,
27
+ U: 21 #:double_underline
28
+ }
29
+ }
30
+
5
31
  class ::String
6
32
 
33
+ def cfmt
34
+ colors = ANSI.colors.keys.join
35
+ opts = ANSI.options.keys.join
36
+ formatted = self
37
+ matches(/\{(?<color>[#{colors}]?)(?<opts>[#{opts}*^]*)\|(?<str>.*?)\}/).each do |m|
38
+ opts = m.opts.split(//).map(&:sym)
39
+ bright = (opts.delete(:'*') || opts.delete(:'^')) ? 90 : 30
40
+ codes = [(ANSI.colors[m.color].to_i + bright)] + ANSI.options.values_at(*opts).compact
41
+ formatted = formatted.sub(m[0], "\033[#{codes.join(';')}m#{m.str}\033[m")
42
+ end
43
+
44
+ formatted
45
+ end
46
+ alias_method :c!, :cfmt
47
+
48
+ def <(*args)
49
+ self.cfmt.%(*args)
50
+ end
51
+
7
52
  def matches(regexp)
8
53
  start = 0
9
54
  matches = []
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mobj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mason
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-06 00:00:00.000000000 Z
11
+ date: 2013-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec