~ubuntu-branches/ubuntu/intrepid/ruby1.9/intrepid-updates

« back to all changes in this revision

Viewing changes to lib/rss/utils.rb

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2007-09-04 16:01:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20070904160117-i15zckg2nhxe9fyw
Tags: 1.9.0+20070830-2ubuntu1
* Sync from Debian; remaining changes:
  - Add -g to CFLAGS.
* Fixes build failure on ia64.
* Fixes build failure with gcc-4.2 on lpia.
* Robustify check for target_os, fixing build failure on lpia.
* Set Ubuntu maintainer address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
  module Utils
3
3
    module_function
4
4
    def to_class_name(name)
5
 
      name.split(/_/).collect do |part|
 
5
      name.split(/[_\-]/).collect do |part|
6
6
        "#{part[0, 1].upcase}#{part[1..-1]}"
7
7
      end.join("")
8
8
    end
9
9
    
10
10
    def get_file_and_line_from_caller(i=0)
11
11
      file, line, = caller[i].split(':')
12
 
      [file, line.to_i]
 
12
      line = line.to_i
 
13
      line += 1 if i.zero?
 
14
      [file, line]
13
15
    end
14
16
 
15
17
    def html_escape(s)
28
30
    def element_initialize_arguments?(args)
29
31
      [true, false].include?(args[0]) and args[1].is_a?(Hash)
30
32
    end
 
33
 
 
34
    module YesCleanOther
 
35
      module_function
 
36
      def parse(value)
 
37
        if [true, false, nil].include?(value)
 
38
          value
 
39
        else
 
40
          case value.to_s
 
41
          when /\Ayes\z/i
 
42
            true
 
43
          when /\Aclean\z/i
 
44
            false
 
45
          else
 
46
            nil
 
47
          end
 
48
        end
 
49
      end
 
50
    end
 
51
 
 
52
    module YesOther
 
53
      module_function
 
54
      def parse(value)
 
55
        if [true, false].include?(value)
 
56
          value
 
57
        else
 
58
          /\Ayes\z/i.match(value.to_s) ? true : false
 
59
        end
 
60
      end
 
61
    end
 
62
 
 
63
    module CSV
 
64
      module_function
 
65
      def parse(value)
 
66
        if value.is_a?(String)
 
67
          value.strip.split(/\s*,\s*/)
 
68
        else
 
69
          value
 
70
        end
 
71
      end
 
72
    end
 
73
 
 
74
    module InheritedReader
 
75
      def inherited_reader(constant_name)
 
76
        base_class = inherited_base
 
77
        result = base_class.const_get(constant_name)
 
78
        found_base_class = false
 
79
        ancestors.reverse_each do |klass|
 
80
          if found_base_class
 
81
            if klass.const_defined?(constant_name)
 
82
              result = yield(result, klass.const_get(constant_name))
 
83
            end
 
84
          else
 
85
            found_base_class = klass == base_class
 
86
          end
 
87
        end
 
88
        result
 
89
      end
 
90
 
 
91
      def inherited_array_reader(constant_name)
 
92
        inherited_reader(constant_name) do |result, current|
 
93
          current + result
 
94
        end
 
95
      end
 
96
 
 
97
      def inherited_hash_reader(constant_name)
 
98
        inherited_reader(constant_name) do |result, current|
 
99
          result.merge(current)
 
100
        end
 
101
      end
 
102
    end
31
103
  end
32
104
end