def transform_many(self, inputs, options=None, **kwargs):
        """
        Override the standard behavior of the transform_many by only
        accepting list inputs which we use to perform the choose operation.

        """

        if not inputs:
            return u''

        #update for Loki issue, return string is only one element
        if not isinstance(inputs, list):
            return inputs

        if options is None:
            options = {}

        separator = expand_special_chargroups(options.get('separator'))

        if separator:
            segments = separator.join(inputs)
        else:
            segments = ','.join(inputs)

        return segments
Exemple #2
0
    def transform(self, str_input, separator=u'', index=0, **kwargs):
        if not str_input:
            return u''

        separator = expand_special_chargroups(separator)

        if separator:
            segments = str_input.split(separator)
        else:
            segments = str_input.split()

        if index == 'all':
            return segments

        if index == 'fields':
            return {
                u'Item {}'.format(i + 1): s
                for i, s in enumerate(segments)
            }

        index = try_parse_number(index, cls=int)
        try:
            return segments[index]
        except:
            pass

        return u''
Exemple #3
0
    def test_expand_chargroups(self):
        tests = [
            ('[:space:]', ' '),
            ('[:s:]', ' '),
            ('[:newline:]', '\n'),
            ('[:n:]', '\n'),
            ('[:return:]', '\r'),
            ('[:r:]', '\r'),
            ('[:r:][:n:]', '\r\n'),
        ]

        for group, expected in tests:
            text = 'hello brave {} new world'
            self.assertEqual(util.expand_special_chargroups(group), expected)
            self.assertEqual(util.expand_special_chargroups(group + group), expected + expected)
            self.assertEqual(util.expand_special_chargroups(text.format(group)), text.format(expected))
Exemple #4
0
 def transform_many(self, inputs, options, **kwargs):
     # use transform_many as we need to know if the user passed an empty array
     # inputs can be a list, so test that out and replace values in a list (if we ever provide that): https://admin.zapier.com/rover/app/ZapierFormatterDevAPI/issues/65/
     # default_value can use special characters: https://admin.zapier.com/rover/app/ZapierFormatterDevAPI/issues/54/
     if not isinstance(inputs, list):
         return self.get_defaulted_value(inputs, options['default_value'])
     elif not inputs:
         # we were provided a line-item field, give them one back
         return [expand_special_chargroups(options['default_value'])]
     else:
         output = []
         for input in inputs:
             output.append(
                 self.get_defaulted_value(input, options['default_value']))
         return output
Exemple #5
0
    def transform_many(self, inputs, options=None, **kwargs):
        """
        Override the standard behavior of the transform_many by only
        accepting list inputs which we use to perform the choose operation.

        """

        output = {}

        # Perform main function of Line item to string:

        if not inputs:
            output["text"] = ""
            output["item_1"] = ""
            output["item_last"] = ""
            return output

        # update for Loki issue, return string is only one element
        if not isinstance(inputs, list):
            output["text"] = inputs
            output["item_1"] = inputs
            output["item_last"] = inputs
            return output

        if options is None:
            options = {}

        separator = expand_special_chargroups(options.get("separator"))

        if separator:
            text_ouput = separator.join(inputs)
        else:
            text_ouput = ",".join(inputs)

        output["text"] = text_ouput

        # Create Separate Fields

        for i, v in enumerate(inputs):
            output["item_" + str(i + 1)] = v
            output["item_last"] = v

        return output
Exemple #6
0
    def transform(self, str_input, separator=u'', index=0, **kwargs):
        if not str_input:
            return u''

        separator = expand_special_chargroups(separator)

        if separator:
            segments = str_input.split(separator)
        else:
            segments = str_input.split()

        if index == 'all':
            return segments

        index = try_parse_number(index, cls=int)
        try:
            return segments[index]
        except:
            pass

        return u''
Exemple #7
0
 def transform(self, str_input, old, new=u'', **kwargs):
     if old:
         old = expand_special_chargroups(old)
     if new:
         new = expand_special_chargroups(new)
     return str_input.replace(old, new) if str_input and old else u''
Exemple #8
0
 def transform(self, str_input, old, new=u'', **kwargs):
     if old:
         old = expand_special_chargroups(old)
     if new:
         new = expand_special_chargroups(new)
     return str_input.replace(old, new) if str_input and old else u''
Exemple #9
0
 def get_defaulted_value(self, input, default_value):
     return input if input is not None and input != "" else expand_special_chargroups(
         default_value)