~ubuntu-branches/ubuntu/oneiric/ctioga2/oneiric

« back to all changes in this revision

Viewing changes to lib/ctioga2/metabuilder/types/strings.rb

  • Committer: Bazaar Package Importer
  • Author(s): Vincent Fourmond
  • Date: 2011-01-24 21:36:06 UTC
  • Revision ID: james.westby@ubuntu.com-20110124213606-9ettx0ugl83z0bzp
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# strings.rb : Different Types to deal with strings
 
2
# Copyright (C) 2006 Vincent Fourmond
 
3
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
17
 
 
18
require 'ctioga2/utils'
 
19
 
 
20
module CTioga2
 
21
 
 
22
  Version::register_svn_info('$Revision: 2 $', '$Date: 2009-04-25 14:03:30 +0200 (Sat, 25 Apr 2009) $')
 
23
 
 
24
 
 
25
  module MetaBuilder
 
26
 
 
27
    # The module Types should be used for all subclasses of
 
28
    # Type, to keep the place clean and tidy.
 
29
    module Types
 
30
 
 
31
      # A String
 
32
      class StringParameter < Type
 
33
 
 
34
        type_name :string
 
35
        
 
36
        def type_name
 
37
          return 'text'
 
38
        end
 
39
        
 
40
        def string_to_type(str)
 
41
          return str
 
42
        end
 
43
      end
 
44
 
 
45
      # A piece of text representing the path to a file.
 
46
      class FileParameter < StringParameter
 
47
 
 
48
        type_name :file
 
49
        
 
50
        # The file filters, Qt style.
 
51
        attr_reader :filter
 
52
 
 
53
        def initialize(type)
 
54
          super(type)
 
55
          @filter = @type[:filter]
 
56
        end
 
57
 
 
58
        def type_name
 
59
          return 'file'
 
60
        end
 
61
 
 
62
      end
 
63
 
 
64
      # A String or a regular expression
 
65
      class StringOrRegexpParameter < Type
 
66
 
 
67
        type_name :string_or_regexp
 
68
        
 
69
        def type_name
 
70
          return 'regexp'
 
71
        end
 
72
        
 
73
        def string_to_type(str)
 
74
          if str =~ /^\/(.*)\/$/
 
75
            return Regexp.new($1)
 
76
          else
 
77
            return str
 
78
          end
 
79
        end
 
80
 
 
81
        def type_to_string(val)
 
82
          if val.is_a? String
 
83
            return val
 
84
          else
 
85
            return "/#{val}/"
 
86
          end
 
87
        end
 
88
 
 
89
      end
 
90
 
 
91
    end
 
92
  end
 
93
end