Coder Social home page Coder Social logo

Comments (7)

cmatskas avatar cmatskas commented on May 14, 2024 1

@bchavez this is freaking awesome! Probably the best response to an issue I've ever got. For this alone, I'll spend some time and raise the PR. Thanks again my friend and keep up the great work :) 👍

from bogus.

bchavez avatar bchavez commented on May 14, 2024 1

Ahhh, now I see. Well, I screwed up that one pretty badly didn't I?

The dyslexia is real. I have no idea why I read "Sort" as "Short" (as in small). Lmao. 😃

My bad.

I'll rename this API to SortCode as originally intended and issue a new release sortly (pun intended). hahaha. 😎

Should be in a few hours, currently putting the final touches on some other new features. 👍

🌙 🌠 "Nothing good happens past 2am..."

from bogus.

bchavez avatar bchavez commented on May 14, 2024

Hi there @cmatskas ,

Thank you for your suggestion. I'm glad you like Bogus 😎. It should be pretty easy to extend Bogus to support ShortCodes. Also, I'd be happy to accept a PR for your feature so others benefit too.

I'm not fimilar with UK ShortCodes but 1) since this is locale specific to the UK and 2) I don't think you would need locale JSON extension storage, you can simply implement your .ShortCode as an extesion method off the Finance data set.

Here is how to do that:

  1. Fork and checkout Bogus.
  2. Run build restore in Command Prompt inside your fresh checkout before using Visual Studio.
  3. Open Visual Studio and create a new file called ExtensionsForUnitedKingdom.cs inside Bogus\Extensions here:

ExtensionsForUnitedKingdom.cs:

namespace Bogus.Extensions.UnitedKingdom
{
   public static class ExtensionsForUnitedKingdom
   {
      public static string ShortCode(this Bogus.DataSets.Finance finance)
      {
         //whatever is needed to create a valid shortcode.
      }
   }
}
  1. Write a unit test in Bogus.Tests\DataSetTests\FinanceTest.cs:

FinanceTest.cs:

[Fact]
public void can_generate_uk_shortcode()
{
   finance.ShortCode().Should().Be("07-24-15");
}
  1. Compile with VS. Test with build test.
  2. If all looks good, build clean and then commit your changes to your fork.
  3. Finally, send in the PR. 😎
  4. We'll wait for CI to check the changes. Review the PR and publish.

Once your changes are published on NuGet, you'll add the new using statement in your program:

using Bogus.Extensions.UnitedKingdom;

var faker = new Faker<BankAccount>()
         .RuleFor( acc => acc.MyUKShortCode, f => f.Finance.ShortCode())

and all UK related extension methods light up over Bogus' API.

Please feel free to ping me at anytime if you need help with anything.

Hope that helps!
Brian

⌚ 🌆 "I just can't wait... I just can't wait... for saturday night..."

from bogus.

bchavez avatar bchavez commented on May 14, 2024

Hi @cmatskas ,

Good news, your feature request for UK banking Short Codes are now available in Bogus v19.

Simply import the Bogus.Extensions.UnitedKingdom namespace as described here:
https://github.com/bchavez/Bogus#api-extension-methods

The .ShortCode() extension method hangs off the Finance data set, so f => f.Finance.ShortCode() should just about do it.

Enjoy :)

Thanks,
Brian

🚶 😎 "So don't delay... act now supplies are running out..."

from bogus.

Nosmadas avatar Nosmadas commented on May 14, 2024

How come they're named ShortCodes here? The OP even says SortCode?

Great extension BTW, just a little confused as a consumer.

@bchavez

from bogus.

bchavez avatar bchavez commented on May 14, 2024

Hi @Nosmadas,

Thanks for your question. The official API is ShortCode() defined here:

public static string ShortCode(this Finance finance, bool includeSeperator = true)

My reference to ShortCodes (with an s) in this thread is in the plural form (as a group) and references the ability to generate more than one ShortCode with Bogus.

Is there something else in the United Kingdom that is also called "ShortCodes" that can cause confusion between ShortCode and ShortCodes?

Thanks,
Brian

💨 🚶 "Bubbles of gas in my brain... Send me off balance, it's not enough"

from bogus.

Nosmadas avatar Nosmadas commented on May 14, 2024

Hey @bchavez

The API looks great.

I was referring to this instead - https://en.wikipedia.org/wiki/Sort_code rather than plural vs singular.

Sort vs Short.

from bogus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.