siefca-MetaBool 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. data/lib/metabool/main.rb +121 -0
  2. data/lib/metabool.rb +23 -0
  3. metadata +54 -0
@@ -0,0 +1,121 @@
1
+ #
2
+ # Easy boolean operations.
3
+ #
4
+ # Author:: Paweł Wilk (mailto:pw@gnu.org)
5
+ # Copyright:: Copyright (c) 2009 Paweł Wilk
6
+ # License:: GNU Lesser General Public License version 3 or higher.
7
+
8
+ # This module contains helpers for evaluating logical expressions.
9
+
10
+ module MetaBool
11
+
12
+ def is_empty?(variable=self)
13
+ if variable.respond_to?(:empty?) && variable.respond_to?(:strip)
14
+ variable.empty? or variable.strip.empty?
15
+ elsif variable.respond_to? :empty?
16
+ variable.empty?
17
+ elsif variable.respond_to? :zero?
18
+ variable.zero?
19
+ else
20
+ !variable ? true : false
21
+ end
22
+ end
23
+
24
+ def is_true?(variable=self)
25
+ r = true
26
+ r = false if variable.kind_of? NilClass
27
+ r = false if variable.kind_of? FalseClass
28
+ return r
29
+ end
30
+
31
+ def is_full?(variable=self); not is_empty?(variable) end
32
+
33
+ def is_positive?(variable=self)
34
+ r = true
35
+ variable = variable.length if variable.kind_of String
36
+ r = variable > 0 if variable.kind_of? Numeric
37
+ r = false if variable.kind_of? NilClass
38
+ r = false if variable.kind_of? FalseClass
39
+ return r
40
+ end
41
+
42
+ def is_negative?(variable=self)
43
+ r = false
44
+ r = variable < 0 if variable.kind_of? Numeric
45
+ return r
46
+ end
47
+
48
+ def is_false?(variable=self); !is_true? variable end
49
+ def to_b(variable=self); is_full? variable end
50
+
51
+ def have?(variable=self); is_full? variable end
52
+ def have_not?(variable=self); is_empty? variable end
53
+
54
+ def do_have?(variable=self); have? variable end
55
+ def have_no?(variable=self); have_not? variable end
56
+ def havent?(variable=self); have_not? variable end
57
+ def dont_have?(variable=self); have_not? variable end
58
+ def do_not_have?(variable=self); have_not? variable end
59
+
60
+ def is_it?(variable=self); is_full? variable end
61
+ def is_it_not?(variable=self); is_false? variable end
62
+ def isnt?(variable=self); is_false? variable end
63
+
64
+ def to_class(klass_name=self)
65
+ parts = klass_name.to_s.split(/::/)
66
+ klass = Kernel
67
+ parts.each do |part|
68
+ klass = klass.const_get(part)
69
+ end
70
+ return klass
71
+ end
72
+
73
+ def class_exists?(name)
74
+ begin
75
+ true if name.to_class
76
+ rescue NameError
77
+ false
78
+ end
79
+ end
80
+
81
+ def show_if_have(variable=self, message=nil)
82
+ message = variable if message.nil?
83
+ have?(variable) ? message : false
84
+ end
85
+
86
+ def show_if_is(variable=self, message=nil)
87
+ message = variable if message.nil?
88
+ is_it?(variable) ? message : false
89
+ end
90
+
91
+ def show_if_it_is(variable=self, message=nil)
92
+ show_if_is(variable, first_txt, second_txt)
93
+ end
94
+
95
+ def if_have(message=nil)
96
+ if block_given? && have?(self)
97
+ yield(message.nil? ? self : message)
98
+ else
99
+ show_if_have(self, message)
100
+ end
101
+ end
102
+
103
+ def if_is(message=nil)
104
+ if block_given? && is_it?(self)
105
+ yield(message.nil? ? self : message)
106
+ else
107
+ show_if_is(self, message)
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ def TrueClass.is_true?(x) x != nil && x != false end
114
+ def TrueClass.is_false?(x) x != nil && x != false end
115
+
116
+
117
+ # #Warranty#
118
+ #
119
+ # This software is provided "as is" and without any express or implied warranties,
120
+ # including, without limitation, the implied warranties of merchantibility and
121
+ # fitness for a particular purpose.
data/lib/metabool.rb ADDED
@@ -0,0 +1,23 @@
1
+ #
2
+ # Easy boolean operations.
3
+ #
4
+ # Author:: Paweł Wilk (mailto:pw@gnu.org)
5
+ # Copyright:: Copyright (c) 2009 Paweł Wilk
6
+ # License:: GNU Lesser General Public License version 3 or higher.
7
+
8
+ # This module contains helpers for evaluating logical expressions.
9
+
10
+ module MetaBool
11
+ # :stopdoc:
12
+ VERSION_CODE = '000004'.freeze
13
+ VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze
14
+ # :startdoc:
15
+ end
16
+
17
+ require 'metabool/main.rb'
18
+
19
+ # #Warranty#
20
+ #
21
+ # This software is provided "as is" and without any express or implied warranties,
22
+ # including, without limitation, the implied warranties of merchantibility and
23
+ # fitness for a particular purpose.
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: siefca-MetaBool
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - "Pawe\xC5\x82 Wilk"
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-03-02 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: MetaBool is small module which helps you to compare objects as they were boolean
17
+ email: pw@gnu.org
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/metabool.rb
26
+ - lib/metabool/main.rb
27
+ has_rdoc: true
28
+ homepage: http://randomseed.pl/metabool
29
+ post_install_message:
30
+ rdoc_options: []
31
+
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: "0"
39
+ version:
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ version:
46
+ requirements: []
47
+
48
+ rubyforge_project:
49
+ rubygems_version: 1.2.0
50
+ signing_key:
51
+ specification_version: 2
52
+ summary: MetaBool is small module which helps you to compare objects as they were boolean
53
+ test_files: []
54
+